diff options
Diffstat (limited to 'src/platform/path.c')
-rw-r--r-- | src/platform/path.c | 17 |
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 |