summaryrefslogtreecommitdiff
path: root/src/platform/path.c
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-17 15:00:53 +1100
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-17 15:00:53 +1100
commit51b4a3fc75351d6ecd2142c228d31a1f7ed52152 (patch)
treec28d0c11b71a56199a6308914a040e18a28b60ef /src/platform/path.c
parent2b83174a87f5a1e4991cc9153309ad0f73450b44 (diff)
fix a bug with dirname seg faulting when passed a string literal
it doesnt like things in readonly memory i guess. now we create an arena for the obj load and create a dynamically allocated copy of the string
Diffstat (limited to 'src/platform/path.c')
-rw-r--r--src/platform/path.c9
1 files changed, 7 insertions, 2 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