diff options
author | David Robillard <d@drobilla.net> | 2020-11-10 09:45:15 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-13 23:05:22 -0500 |
commit | f7d10ea309fb52d09a58b2832fe4a09a120b16aa (patch) | |
tree | 3b5d870063d0565ac29334ffb64363fdac23b012 /src | |
parent | b9cc3b642a9365c033c1fa31458d7822b42d0913 (diff) | |
download | serd-f7d10ea309fb52d09a58b2832fe4a09a120b16aa.tar.gz serd-f7d10ea309fb52d09a58b2832fe4a09a120b16aa.tar.bz2 serd-f7d10ea309fb52d09a58b2832fe4a09a120b16aa.zip |
Add serd_canonical_path()
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 +} |