mirror of https://github.com/getdnsapi/getdns.git
fread with mingw32 compiled can return < file sz,
because it automatically converts \r\n into \n
This commit is contained in:
parent
b9260f8fca
commit
078c50f1b2
|
@ -543,6 +543,7 @@ int parse_config_file(const char *fn, int report_open_failure)
|
|||
FILE *fh;
|
||||
char *config_file = NULL;
|
||||
long config_file_sz;
|
||||
size_t read_sz;
|
||||
|
||||
if (!(fh = fopen(fn, "r"))) {
|
||||
if (report_open_failure)
|
||||
|
@ -567,13 +568,14 @@ int parse_config_file(const char *fn, int report_open_failure)
|
|||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
rewind(fh);
|
||||
if (fread(config_file, 1, config_file_sz, fh) != (size_t)config_file_sz) {
|
||||
read_sz = fread(config_file, 1, config_file_sz + 1, fh);
|
||||
if (read_sz > config_file_sz || ferror(fh) || !feof(fh)) {
|
||||
fprintf( stderr, "An error occurred while reading \"%s\": %s\n"
|
||||
, fn, strerror(errno));
|
||||
fclose(fh);
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
config_file[config_file_sz] = 0;
|
||||
config_file[read_sz] = 0;
|
||||
fclose(fh);
|
||||
parse_config(config_file, strstr(fn, ".yml") != NULL);
|
||||
free(config_file);
|
||||
|
|
Loading…
Reference in New Issue