From a39e4ae65d5e4bab2cbf3662834d4ab78857080e Mon Sep 17 00:00:00 2001 From: Alexis Campailla Date: Tue, 24 Feb 2015 16:28:33 +0100 Subject: [PATCH] Handle absolute paths for config files --- src/util.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/util.c b/src/util.c index a81a81e0..c37da017 100644 --- a/src/util.c +++ b/src/util.c @@ -40,6 +40,7 @@ #else #include "win32_Interop/win32fixes.h" #include // for getcwd +#include // for PathIsRelative #endif #include #include @@ -482,6 +483,7 @@ void getRandomHexChars(char *p, unsigned int len) { * The function does not try to normalize everything, but only the obvious * case of one or more "../" appearning at the start of "filename" * relative path. */ +#ifndef _WIN32 sds getAbsolutePath(char *filename) { char cwd[1024]; sds abspath; @@ -526,6 +528,27 @@ sds getAbsolutePath(char *filename) { sdsfree(relpath); return abspath; } +#else +sds getAbsolutePath(char *filename) { + char fullPath[MAX_PATH]; + DWORD gfpnResult; + sds abspath; + sds relpath = sdsnew(filename); + + relpath = sdstrim(relpath," \r\n\t"); + + if (!PathIsRelative(relpath)) return relpath; + + gfpnResult = GetFullPathNameA(relpath, sizeof(fullPath), fullPath, NULL); + sdsfree(relpath); + + if (gfpnResult == 0 || gfpnResult > sizeof(fullPath)) { + return NULL; + } + abspath = sdsnew(fullPath); + return abspath; +} +#endif /* Return true if the specified path is just a file basename without any * relative or absolute path. This function just checks that no / or \ -- GitLab