summaryrefslogtreecommitdiff
path: root/src/platform/file.c
diff options
context:
space:
mode:
authoromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-03-27 22:09:03 +1100
committeromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-03-27 22:09:03 +1100
commitff907c6ffa7ed0a7c6ce938b40a6c223dd0a3b9d (patch)
tree095d3153a42b850fb32287c1aef206e9fba5faab /src/platform/file.c
parent80cdd4f2b1c2a3355926b59a85e14100b3daa7b7 (diff)
start going through Kohi episode 26
Diffstat (limited to 'src/platform/file.c')
-rw-r--r--src/platform/file.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/platform/file.c b/src/platform/file.c
index ec9259a..ac5014d 100644
--- a/src/platform/file.c
+++ b/src/platform/file.c
@@ -61,3 +61,33 @@ str8_opt str8_from_file(arena *a, str8 path) {
return result;
}
+
+FileData load_spv_file(const char *path) {
+ FILE *f = fopen(path, "rb");
+ if (f == NULL) {
+ perror("Error opening file");
+ return (FileData){NULL, 0};
+ }
+
+ fseek(f, 0, SEEK_END);
+ long fsize = ftell(f);
+ rewind(f);
+
+ char *data = (char *)malloc(fsize);
+ if (data == NULL) {
+ perror("Memory allocation failed");
+ fclose(f);
+ return (FileData){NULL, 0};
+ }
+
+ size_t bytesRead = fread(data, 1, fsize, f);
+ if (bytesRead < fsize) {
+ perror("Failed to read the entire file");
+ free(data);
+ fclose(f);
+ return (FileData){NULL, 0};
+ }
+
+ fclose(f);
+ return (FileData){data, bytesRead};
+} \ No newline at end of file