Skip to content

Commit

Permalink
fixup! mingw: ensure getcwd() reports the correct case
Browse files Browse the repository at this point in the history
The return value of GetCurrentDirectoryW() upon errors is actually 0, not
negative (it cannot be negative, as DWORD is an *unsigned* data type).

Also, when converting from _wgetcwd(), I forgot to add errno explicitly...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed May 5, 2017
1 parent c9743bc commit d4696aa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compat/mingw.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1031,8 +1031,10 @@ char *mingw_getcwd(char *pointer, int len)
HANDLE, LPWSTR, DWORD, DWORD); HANDLE, LPWSTR, DWORD, DWORD);
DWORD ret = GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd); DWORD ret = GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd);


if (ret < 0 || ret >= ARRAY_SIZE(cwd)) if (!ret || ret >= ARRAY_SIZE(cwd)) {
errno = ret ? ENAMETOOLONG : err_win_to_posix(GetLastError());
return NULL; return NULL;
}
ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer)); ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer));
if (!ret && GetLastError() == ERROR_ACCESS_DENIED && if (!ret && GetLastError() == ERROR_ACCESS_DENIED &&
INIT_PROC_ADDR(GetFinalPathNameByHandleW)) { INIT_PROC_ADDR(GetFinalPathNameByHandleW)) {
Expand Down

0 comments on commit d4696aa

Please sign in to comment.