diff options
Diffstat (limited to 'src/platform')
-rw-r--r-- | src/platform/file.c | 30 | ||||
-rw-r--r-- | src/platform/file.h | 9 | ||||
-rw-r--r-- | src/platform/mutex.c | 9 | ||||
-rw-r--r-- | src/platform/mutex.h | 28 | ||||
-rw-r--r-- | src/platform/path.c | 6 | ||||
-rw-r--r-- | src/platform/thread.c | 0 | ||||
-rw-r--r-- | src/platform/thread.h | 17 |
7 files changed, 95 insertions, 4 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 diff --git a/src/platform/file.h b/src/platform/file.h index 8bb22c8..a8aa8ea 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 diff --git a/src/platform/mutex.c b/src/platform/mutex.c new file mode 100644 index 0000000..2aeb825 --- /dev/null +++ b/src/platform/mutex.c @@ -0,0 +1,9 @@ +#include "mutex.h" + +#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC) +// TODO: implement in terms of pthreads +#endif + +#if defined(CEL_PLATFORM_WINDOWS) +// TODO: implement using win32 api +#endif
\ No newline at end of file diff --git a/src/platform/mutex.h b/src/platform/mutex.h new file mode 100644 index 0000000..a0a4208 --- /dev/null +++ b/src/platform/mutex.h @@ -0,0 +1,28 @@ +/** + * @file mutex.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-04-27 + * + * @copyright Copyright (c) 2024 + * + */ +#include <stdbool.h> + +typedef struct cel_mutex cel_mutex; + +cel_mutex mutex_create(); + +void mutex_destroy(cel_mutex* mutex); + +/** @brief Blocks until the mutex can be acquired. if returns false then an error occurred and can + * be checked (TODO) */ +bool mutex_lock(cel_mutex* mutex); + +/** @brief Tries to acquire the mutex like `mutex_lock` but returns immediately if the mutex has + * already been locked */ +bool mutex_try_lock(cel_mutex* mutex); + +/** @brief Releases a mutex. If it is already unlocked then does nothing */ +void mutex_unlock(cel_mutex* mutex);
\ No newline at end of file diff --git a/src/platform/path.c b/src/platform/path.c index 9572941..e49aa3a 100644 --- a/src/platform/path.c +++ b/src/platform/path.c @@ -1,12 +1,12 @@ #include "path.h" -#include <libgen.h> #include <stdlib.h> #include <string.h> #include "mem.h" #include "str.h" #if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC) +#include <libgen.h> path_opt path_parent(arena* a, const char* path) { // Duplicate the string because dirname doesnt like const literals char* path_copy = arena_alloc(a, strlen(path) + 1); @@ -16,5 +16,5 @@ path_opt path_parent(arena* a, const char* path) { } #endif #ifdef CEL_PLATFORM_WINDOWS -// TODO: path_opt path_parent(const char* path) -#endif
\ No newline at end of file +path_opt path_parent(arena* a, const char* path) {} +#endif diff --git a/src/platform/thread.c b/src/platform/thread.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/platform/thread.c diff --git a/src/platform/thread.h b/src/platform/thread.h new file mode 100644 index 0000000..af07d3f --- /dev/null +++ b/src/platform/thread.h @@ -0,0 +1,17 @@ +/** + * @file thread.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-04-27 + * + * @copyright Copyright (c) 2024 + * + */ + +typedef struct cel_thread cel_thread; + +cel_thread thread_create(); +void thread_destroy(cel_thread* thread); + +// join
\ No newline at end of file |