diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-04-24 21:22:53 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 7f524c427597cc998f243769b0e22e4f450c55cf (patch) | |
tree | 0dba782c2214d1ce5309ba71cfd3dddaee4a52a1 /src/std | |
parent | 328a9c8310e8bab250b04e9e001ab0d890d33074 (diff) |
Progressing on bytecode (to c), fix ssa resolving multiple times
Diffstat (limited to 'src/std')
-rw-r--r-- | src/std/file.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/std/file.c b/src/std/file.c index 7de2b6c..84f4b0c 100644 --- a/src/std/file.c +++ b/src/std/file.c @@ -192,11 +192,12 @@ static CHECK_RESULT int file_get_type(const char *filepath, FileType *type) { return 0; } -int read_whole_file(const char *filepath, char **data, usize *size) { +int read_whole_file(const char *filepath, Buffer *data_result) { FileType file_type; FILE *file; int result; usize bytes_read; + usize size; return_if_error(file_get_type(filepath, &file_type)); if(file_type != REGULAR) { @@ -218,24 +219,24 @@ int read_whole_file(const char *filepath, char **data, usize *size) { goto cleanup; } - *size = ftell(file); + size = ftell(file); result = fseek(file, 0, SEEK_SET); if(result != 0) { result = ferror(file); goto cleanup; } - if(*size > MAX_FILE_SIZE) { + if(size > MAX_FILE_SIZE) { amal_log_error("File %s is too large (larger than 48 megabytes)", filepath); result = -1; goto cleanup; } - cleanup_if_error(am_malloc(*size, (void**)data)); - bytes_read = fread(*data, 1, *size, file); - if(bytes_read != *size) { + assert(data_result->capacity == 0 && data_result->size == 0); + cleanup_if_error(buffer_append_empty(data_result, size)); + bytes_read = fread(data_result->data, 1, data_result->size, file); + if(bytes_read != size) result = ferror(file); - } cleanup: fclose(file); |