diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -7,7 +7,7 @@ If errors occur, return non-zero; otherwise the return value is zero. - + Note that *str should be already allocated. Note that the length of the string str is actually 1+length, and @@ -29,16 +29,18 @@ read_entire_file(const char *file_name, char **str, NUM *len) fseek(file, 0, SEEK_END); file_size = ftell(file); fseek(file, 0, SEEK_SET); - + *len = 1+file_size; - *str = realloc(*str, 1+file_size); - - if (*str == NULL) { + char *newstr = realloc(*str, 1+file_size); + + if (newstr == NULL) { fleprintf0("Cannot realloc\n"); return 1; } + *str = newstr; + fread(*str, sizeof(char), file_size, file); fclose(file); |