diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/system.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/system.c b/src/system.c index c02f2d3c..61635591 100644 --- a/src/system.c +++ b/src/system.c @@ -16,10 +16,13 @@ #include "system.h" +#include "serd/serd.h" #include "serd_config.h" #ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN 1 # include <malloc.h> +# include <windows.h> #endif #include <stdio.h> @@ -85,3 +88,25 @@ serd_free_aligned(void* const ptr) free(ptr); #endif } + +char* +serd_canonical_path(const char* const path) +{ +#ifdef _WIN32 + const DWORD size = GetFullPathName(path, 0, NULL, NULL); + if (size == 0) { + return NULL; + } + + char* const out = (char*)calloc(size, 1); + const DWORD ret = GetFullPathName(path, MAX_PATH, out, NULL); + if (ret == 0 || ret >= size) { + free(out); + return NULL; + } + + return out; +#else + return path ? realpath(path, NULL) : NULL; +#endif +} |