summaryrefslogtreecommitdiff
path: root/src/platform/file.c
diff options
context:
space:
mode:
authoromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-04-04 20:25:40 +1100
committeromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-04-04 20:25:40 +1100
commitbb889d2edc1cc72b939edf47a2e03b7569c1a722 (patch)
tree59b7744d44bda7768ba908224a18d6a5046b186f /src/platform/file.c
parent1047d08258f6c56f5fa8067cc65694b1b5798602 (diff)
parent6a95b047998c0e0dcfdf60d17cf2cd0bd0bfee12 (diff)
Merge branch 'cel-60-scaffold-vulkan' into cel-67-load-animation-data-from-gltf
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..6030620 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