--- parser3/src/main/pa_common.C 2020/11/16 21:22:36 1.316 +++ parser3/src/main/pa_common.C 2020/12/03 22:48:09 1.320 @@ -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.316 2020/11/16 21:22:36 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.320 2020/12/03 22:48:09 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; // some maybe-undefined constants @@ -110,18 +110,16 @@ int pa_get_valid_file_options_count(Hash #ifndef DOXYGEN struct File_read_action_info { char **data; size_t *data_size; - char* buf; size_t offset; size_t limit; + char* buf; uint64_t offset; size_t limit; }; #endif static void file_read_action(struct stat& finfo, int f, const String& file_spec, void *context) { 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); + size_t to_read_size = check_file_size(info.limit && info.limit < finfo.st_size ? info.limit : finfo.st_size, &file_spec); if(to_read_size) { if(info.offset) - lseek(f, info.offset, SEEK_SET); + pa_lseek(f, info.offset, SEEK_SET); // seek never fails as POSIX allows the file offset to be set beyond the EOF *info.data = info.buf ? info.buf : (char *)pa_malloc_atomic(to_read_size+1); ssize_t result = read(f, *info.data, to_read_size); if(result<0) @@ -136,7 +134,7 @@ static void file_read_action(struct stat } } -File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem, char* buf, size_t offset, size_t limit) { +File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem, char* buf, uint64_t offset, size_t limit) { File_read_result result = {false, 0, 0, 0}; File_read_action_info info = {&result.str, &result.length, buf, offset, limit}; @@ -532,7 +530,7 @@ bool file_stat(const String& file_spec, } size_t check_file_size(uint64_t size, const String* file_spec){ - if(size > pa_file_size_limit) + if(size > (uint64_t)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; } @@ -669,6 +667,15 @@ char *pa_strcat(const char *a, const cha return result; } +const char *pa_filename(const char *path){ + if(!path) + return NULL; + for(const char *c = path + strlen(path) - 1; c >= path; c--) { + if(*c == '/' || *c == '\\') + return c+1; + } + return path; +} // format: %[flags][width][.precision]type http://msdn.microsoft.com/ru-ru/library/56e442dc(en-us,VS.80).aspx // flags: '-', '+', ' ', '#', '0' http://msdn.microsoft.com/ru-ru/library/8aky45ct(en-us,VS.80).aspx