From 15af852fed398045334bc5e909f044f9b40c2476 Mon Sep 17 00:00:00 2001 From: Joshua Rowe Date: Sat, 3 Aug 2024 03:49:44 +1000 Subject: add windows implementation of path_parent() --- src/platform/path.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') 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 +#include +#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 -- cgit v1.2.3-70-g09d2