summaryrefslogtreecommitdiff
path: root/src/platform/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/path.c')
-rw-r--r--src/platform/path.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/platform/path.c b/src/platform/path.c
new file mode 100644
index 0000000..9572941
--- /dev/null
+++ b/src/platform/path.c
@@ -0,0 +1,20 @@
+#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(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
+#ifdef CEL_PLATFORM_WINDOWS
+// TODO: path_opt path_parent(const char* path)
+#endif \ No newline at end of file