--- parser3/src/main/pa_common.C 2019/11/23 23:48:41 1.310 +++ parser3/src/main/pa_common.C 2020/10/14 21:22:59 1.313 @@ -29,7 +29,7 @@ #define pa_mkdir(path, mode) mkdir(path, mode) #endif -volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.310 2019/11/23 23:48:41 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; +volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.313 2020/10/14 21:22:59 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; // some maybe-undefined constants @@ -118,7 +118,7 @@ static void file_read_action(struct stat File_read_action_info& info = *static_cast(context); size_t to_read_size = info.limit; if(!to_read_size) - to_read_size = check_file_size(finfo.st_size, file_spec); + to_read_size = check_file_size(finfo.st_size, &file_spec); if(to_read_size) { if(info.offset) lseek(f, info.offset, SEEK_SET); @@ -407,7 +407,19 @@ static size_t get_dir(char* fname, size_ return pos; } -static bool entry_readable(char* fname, bool need_dir) { +bool entry_exists(const char* fname, struct stat *afinfo) { + struct stat lfinfo; + bool result=pa_stat(fname, &lfinfo)==0; + if(afinfo) + *afinfo=lfinfo; + return result; +} + +bool entry_exists(const String& file_spec) { + return entry_exists(file_spec.taint_cstr(String::L_FILE_SPEC), 0); +} + +static bool entry_ifdir(char *fname, bool need_dir) { if(need_dir){ size_t size=strlen(fname); while(size) { @@ -420,15 +432,15 @@ static bool entry_readable(char* fname, } struct stat finfo; - if(access(fname, R_OK)==0 && entry_exists(fname, &finfo)) { + if(entry_exists(fname, &finfo)) { bool is_dir=(finfo.st_mode&S_IFDIR) != 0; return is_dir==need_dir; } return false; } -static bool entry_readable(const String& file_spec, bool need_dir) { - return entry_readable(file_spec.taint_cstrm(String::L_FILE_SPEC), need_dir); +static bool entry_ifdir(const String& file_spec, bool need_dir) { + return entry_ifdir(file_spec.taint_cstrm(String::L_FILE_SPEC), need_dir); } // throws nothing! [this is required in file_move & file_delete] @@ -437,7 +449,7 @@ static void rmdir(const String& file_spe size_t length=strlen(dir_spec); while( (length=get_dir(dir_spec, length)) && (length > pos_after) ){ #ifdef _MSC_VER - if(!entry_readable(dir_spec, true)) + if(!entry_ifdir(dir_spec, true)) break; DWORD attrs=GetFileAttributes(dir_spec); if( @@ -483,25 +495,12 @@ void file_move(const String& old_spec, c } -bool entry_exists(const char* fname, struct stat *afinfo) { - struct stat lfinfo; - bool result=pa_stat(fname, &lfinfo)==0; - if(afinfo) - *afinfo=lfinfo; - return result; -} - -bool entry_exists(const String& file_spec) { - const char* fname=file_spec.taint_cstr(String::L_FILE_SPEC); - return entry_exists(fname, 0); -} - bool file_exist(const String& file_spec) { - return entry_readable(file_spec, false); + return entry_ifdir(file_spec, false); } bool dir_exists(const String& file_spec) { - return entry_readable(file_spec, true); + return entry_ifdir(file_spec, true); } const String* file_exist(const String& path, const String& name) { @@ -532,9 +531,9 @@ bool file_stat(const String& file_spec, return true; } -size_t check_file_size(uint64_t size, const String& file_spec){ +size_t check_file_size(uint64_t size, const String* file_spec){ if(size > pa_file_size_limit) - throw Exception(PARSER_RUNTIME, &file_spec, "content size of %.15g bytes exceeds the limit (%.15g bytes)", (double)size, (double)pa_file_size_limit); + throw Exception(PARSER_RUNTIME, file_spec, "content size of %.15g bytes exceeds the limit (%.15g bytes)", (double)size, (double)pa_file_size_limit); return (size_t)size; }