From f7d10ea309fb52d09a58b2832fe4a09a120b16aa Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 09:45:15 +0100 Subject: Add serd_canonical_path() --- src/system.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/system.c') 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 +# include #endif #include @@ -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 +} -- cgit v1.2.1