summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/file.c30
-rw-r--r--src/platform/file.h9
2 files changed, 38 insertions, 1 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
diff --git a/src/platform/file.h b/src/platform/file.h
index 8bb22c8..83d1317 100644
--- a/src/platform/file.h
+++ b/src/platform/file.h
@@ -16,4 +16,11 @@ typedef struct str8_opt {
const char* string_from_file(const char* path);
-str8_opt str8_from_file(arena* a, str8 path); \ No newline at end of file
+str8_opt str8_from_file(arena* a, str8 path);
+
+typedef struct {
+ char *data;
+ size_t size;
+} FileData;
+
+FileData load_spv_file(const char *path); \ No newline at end of file