summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/path.c9
-rw-r--r--src/platform/path.h2
2 files changed, 8 insertions, 3 deletions
diff --git a/src/platform/path.c b/src/platform/path.c
index e67102b..9572941 100644
--- a/src/platform/path.c
+++ b/src/platform/path.c
@@ -1,12 +1,17 @@
#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)
-path_opt path_parent(const char* path) {
- char* path_dirname = dirname(path);
+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);
+ strcpy(path_copy, path);
+ char* path_dirname = dirname(path_copy);
return (path_opt){ .path = str8_cstr_view(path_dirname), .has_value = true };
}
#endif
diff --git a/src/platform/path.h b/src/platform/path.h
index 0ec6993..73063ea 100644
--- a/src/platform/path.h
+++ b/src/platform/path.h
@@ -13,4 +13,4 @@ typedef struct path_opt {
bool has_value;
} path_opt;
-path_opt path_parent(const char* path); // TODO: convert to using str8 \ No newline at end of file
+path_opt path_parent(arena* a, const char* path); // TODO: convert to using str8 \ No newline at end of file