summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-05-07 13:58:01 +0200
committernulltoken <emeric.fermas@gmail.com>2012-05-08 10:05:18 +0200
commit9abb5bca5d094f832d2c68342aefc8809ec8ca09 (patch)
treec8efa3ba0f237ef631d402a740d1797a68fc1203 /src/win32
parent46811561ae19701d4d0fc4b00113667f81961dfc (diff)
downloadlibgit2-9abb5bca5d094f832d2c68342aefc8809ec8ca09.tar.gz
compat: make p_realpath Windows implementation be a bit more POSIX compliant and fail if the provided path does not lead to an existing entry
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/posix_w32.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 617291899..10de70da8 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -326,7 +326,7 @@ int p_hide_directory__w32(const char *path)
char *p_realpath(const char *orig_path, char *buffer)
{
- int ret;
+ int ret, buffer_sz = 0;
wchar_t* orig_path_w = gitwin_to_utf16(orig_path);
wchar_t* buffer_w = (wchar_t*)git__malloc(GIT_PATH_MAX * sizeof(wchar_t));
@@ -336,13 +336,14 @@ char *p_realpath(const char *orig_path, char *buffer)
ret = GetFullPathNameW(orig_path_w, GIT_PATH_MAX, buffer_w, NULL);
git__free(orig_path_w);
- if (!ret || ret > GIT_PATH_MAX) {
+ /* According to MSDN, a return value equals to zero means a failure. */
+ if (ret == 0 || ret > GIT_PATH_MAX) {
buffer = NULL;
goto done;
}
if (buffer == NULL) {
- int buffer_sz = WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, NULL, 0, NULL, NULL);
+ buffer_sz = WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, NULL, 0, NULL, NULL);
if (!buffer_sz ||
!(buffer = (char *)git__malloc(buffer_sz)) ||
@@ -350,10 +351,22 @@ char *p_realpath(const char *orig_path, char *buffer)
{
git__free(buffer);
buffer = NULL;
+ goto done;
}
} else {
- if (!WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, buffer, GIT_PATH_MAX, NULL, NULL))
+ if (!WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, buffer, GIT_PATH_MAX, NULL, NULL)) {
buffer = NULL;
+ goto done;
+ }
+ }
+
+ if (!git_path_exists(buffer))
+ {
+ if (buffer_sz > 0)
+ git__free(buffer);
+
+ buffer = NULL;
+ errno = ENOENT;
}
done: