summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Rowe <omniscient.oce@gmail.com>2024-08-03 03:49:44 +1000
committerJoshua Rowe <omniscient.oce@gmail.com>2024-08-03 03:49:44 +1000
commit15af852fed398045334bc5e909f044f9b40c2476 (patch)
treed676583751f121ef9c082cef1a267f87b32ac561 /src
parente14156ed8a7a3cfb60c977b3a331c0424faa0051 (diff)
add windows implementation of path_parent()
Diffstat (limited to 'src')
-rw-r--r--src/platform/path.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/platform/path.c b/src/platform/path.c
index 31fa59c..3607089 100644
--- a/src/platform/path.c
+++ b/src/platform/path.c
@@ -16,5 +16,20 @@ path_opt path_parent(arena* a, const char* path) {
}
#endif
#ifdef CEL_PLATFORM_WINDOWS
-path_opt path_parent(arena* a, const char* path) {}
+#include <windows.h>
+#include <shlwapi.h>
+#pragma comment(lib, "Shlwapi.lib")
+
+path_opt path_parent(arena* a, const char* path) {
+ // Duplicate the string because PathRemoveFileSpec mutates in-place
+ size_t len = strlen(path) + 1;
+ char* path_copy = arena_alloc(a, len);
+ strcpy_s(path_copy, len, path);
+
+ if (PathRemoveFileSpecA(path_copy)) {
+ return (path_opt){ .path = Str8_cstr_view(path_copy), .has_value = true };
+ } else {
+ return (path_opt){ .has_value = false};
+ }
+}
#endif