diff options
Diffstat (limited to 'src/system')
-rw-r--r-- | src/system/fileutils.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/system/fileutils.c b/src/system/fileutils.c index 7bd6859..dc8eaca 100644 --- a/src/system/fileutils.c +++ b/src/system/fileutils.c @@ -4,7 +4,9 @@ #include <unistd.h> #include <stdlib.h> -int mgl_load_file(const char *filepath, mgl_filedata *filedata) { +int mgl_load_file(const char *filepath, mgl_filedata *filedata, mgl_file_load_options *load_options) { + const bool null_terminated = load_options ? load_options->null_terminated : false; + int fd = open(filepath, O_RDONLY); if(fd == -1) return -1; @@ -20,7 +22,7 @@ int mgl_load_file(const char *filepath, mgl_filedata *filedata) { return -1; } - unsigned char *data = malloc(st.st_size); + unsigned char *data = malloc(st.st_size + (null_terminated ? 1 : 0)); if(!data) { close(fd); return -1; @@ -32,6 +34,9 @@ int mgl_load_file(const char *filepath, mgl_filedata *filedata) { return -1; } + if(null_terminated) + data[st.st_size] = '\0'; + filedata->data = data; filedata->size = st.st_size; |