Skip to content

Commit

Permalink
Merge pull request #606 from skvoboo/issue_598
Browse files Browse the repository at this point in the history
Use GetFinalPathNameByHandleW instead of GetLongPathNameW to get full path
  • Loading branch information
dscho committed Jan 21, 2016
2 parents 78ce6bc + 3700315 commit a41b148
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,11 +952,28 @@ char *mingw_getcwd(char *pointer, int len)
{
int i;
wchar_t cwd[MAX_PATH], wpointer[MAX_PATH];
DECLARE_PROC_ADDR(kernel32.dll, DWORD, GetFinalPathNameByHandleW,
HANDLE, LPWSTR, DWORD, DWORD);
DWORD ret = GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd);

if (ret < 0 || ret >= ARRAY_SIZE(cwd))
return NULL;
ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer));
if (!ret && GetLastError() == ERROR_ACCESS_DENIED &&
INIT_PROC_ADDR(GetFinalPathNameByHandleW)) {
HANDLE hnd = CreateFileW(cwd, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (hnd == INVALID_HANDLE_VALUE)
return NULL;
ret = GetFinalPathNameByHandleW(hnd, wpointer, ARRAY_SIZE(wpointer), 0);
CloseHandle(hnd);
if (!ret || ret >= ARRAY_SIZE(wpointer))
return NULL;
if (xwcstoutf(pointer, normalize_ntpath(wpointer), len) < 0)
return NULL;
return pointer;
}
if (!ret || ret >= ARRAY_SIZE(wpointer))
return NULL;
if (xwcstoutf(pointer, wpointer, len) < 0)
Expand Down

0 comments on commit a41b148

Please sign in to comment.