diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-06 09:09:43 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-06 09:09:43 +0000 |
commit | 8ebe81483b8759c36c9aa5015044d8e3d2c50fd5 (patch) | |
tree | 4d0ec4de054cbf99a7aef8e250c346e96a100323 | |
parent | 24b237331a679a2e1d7f80d2b3168622784b084a (diff) | |
download | busybox-w32-8ebe81483b8759c36c9aa5015044d8e3d2c50fd5.tar.gz busybox-w32-8ebe81483b8759c36c9aa5015044d8e3d2c50fd5.tar.bz2 busybox-w32-8ebe81483b8759c36c9aa5015044d8e3d2c50fd5.zip |
win32: let realpath(3) succeed on WinXP/ReactOS
Allow realpath(3) to return successfully on platforms that don't
support GetFinalPathNameByHandleA(). It may still have done some
useful work.
-rw-r--r-- | win32/mingw.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 240f87b21..dda2e9a60 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1000,29 +1000,35 @@ int link(const char *oldpath, const char *newpath) | |||
1000 | 1000 | ||
1001 | static char *resolve_symlinks(char *path) | 1001 | static char *resolve_symlinks(char *path) |
1002 | { | 1002 | { |
1003 | HANDLE h = INVALID_HANDLE_VALUE; | 1003 | HANDLE h; |
1004 | DWORD status; | ||
1005 | char *ptr = NULL; | ||
1004 | DECLARE_PROC_ADDR(DWORD, GetFinalPathNameByHandleA, HANDLE, | 1006 | DECLARE_PROC_ADDR(DWORD, GetFinalPathNameByHandleA, HANDLE, |
1005 | LPSTR, DWORD, DWORD); | 1007 | LPSTR, DWORD, DWORD); |
1006 | 1008 | ||
1007 | if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) | ||
1008 | return NULL; | ||
1009 | |||
1010 | /* need a file handle to resolve symlinks */ | 1009 | /* need a file handle to resolve symlinks */ |
1011 | h = CreateFileA(path, 0, 0, NULL, OPEN_EXISTING, | 1010 | h = CreateFileA(path, 0, 0, NULL, OPEN_EXISTING, |
1012 | FILE_FLAG_BACKUP_SEMANTICS, NULL); | 1011 | FILE_FLAG_BACKUP_SEMANTICS, NULL); |
1013 | if (h != INVALID_HANDLE_VALUE) { | 1012 | if (h != INVALID_HANDLE_VALUE) { |
1013 | if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) { | ||
1014 | ptr = path; | ||
1015 | goto end; | ||
1016 | } | ||
1017 | |||
1014 | /* normalize the path and return it on success */ | 1018 | /* normalize the path and return it on success */ |
1015 | DWORD status = GetFinalPathNameByHandleA(h, path, MAX_PATH, | 1019 | status = GetFinalPathNameByHandleA(h, path, MAX_PATH, |
1016 | FILE_NAME_NORMALIZED|VOLUME_NAME_DOS); | 1020 | FILE_NAME_NORMALIZED|VOLUME_NAME_DOS); |
1017 | CloseHandle(h); | ||
1018 | if (status != 0 && status < MAX_PATH) { | 1021 | if (status != 0 && status < MAX_PATH) { |
1019 | /* skip '\\?\' prefix */ | 1022 | /* skip '\\?\' prefix */ |
1020 | return (!strncmp(path, "\\\\?\\", 4)) ? (path + 4) : path; | 1023 | ptr = (!strncmp(path, "\\\\?\\", 4)) ? (path + 4) : path; |
1024 | goto end; | ||
1021 | } | 1025 | } |
1022 | } | 1026 | } |
1023 | 1027 | ||
1024 | errno = err_win_to_posix(); | 1028 | errno = err_win_to_posix(); |
1025 | return NULL; | 1029 | end: |
1030 | CloseHandle(h); | ||
1031 | return ptr; | ||
1026 | } | 1032 | } |
1027 | 1033 | ||
1028 | /* | 1034 | /* |