Skip to content

Commit d4696aa

Browse files
committed
fixup! mingw: ensure getcwd() reports the correct case
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 <[email protected]>
1 parent c9743bc commit d4696aa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compat/mingw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,10 @@ char *mingw_getcwd(char *pointer, int len)
10311031
HANDLE, LPWSTR, DWORD, DWORD);
10321032
DWORD ret = GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd);
10331033

1034-
if (ret < 0 || ret >= ARRAY_SIZE(cwd))
1034+
if (!ret || ret >= ARRAY_SIZE(cwd)) {
1035+
errno = ret ? ENAMETOOLONG : err_win_to_posix(GetLastError());
10351036
return NULL;
1037+
}
10361038
ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer));
10371039
if (!ret && GetLastError() == ERROR_ACCESS_DENIED &&
10381040
INIT_PROC_ADDR(GetFinalPathNameByHandleW)) {

0 commit comments

Comments
 (0)