@@ -1150,18 +1150,16 @@ char *mingw_getcwd(char *pointer, int len)
1150
1150
{
1151
1151
wchar_t cwd [MAX_PATH ], wpointer [MAX_PATH ];
1152
1152
DWORD ret = GetCurrentDirectoryW (ARRAY_SIZE (cwd ), cwd );
1153
+ HANDLE hnd ;
1153
1154
1154
1155
if (!ret || ret >= ARRAY_SIZE (cwd )) {
1155
1156
errno = ret ? ENAMETOOLONG : err_win_to_posix (GetLastError ());
1156
1157
return NULL ;
1157
1158
}
1158
- ret = GetLongPathNameW (cwd , wpointer , ARRAY_SIZE (wpointer ));
1159
- if (!ret && GetLastError () == ERROR_ACCESS_DENIED ) {
1160
- HANDLE hnd = CreateFileW (cwd , 0 ,
1161
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , NULL ,
1162
- OPEN_EXISTING , FILE_FLAG_BACKUP_SEMANTICS , NULL );
1163
- if (hnd == INVALID_HANDLE_VALUE )
1164
- return NULL ;
1159
+ hnd = CreateFileW (cwd , 0 ,
1160
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , NULL ,
1161
+ OPEN_EXISTING , FILE_FLAG_BACKUP_SEMANTICS , NULL );
1162
+ if (hnd != INVALID_HANDLE_VALUE ) {
1165
1163
ret = GetFinalPathNameByHandleW (hnd , wpointer , ARRAY_SIZE (wpointer ), 0 );
1166
1164
CloseHandle (hnd );
1167
1165
if (!ret || ret >= ARRAY_SIZE (wpointer ))
@@ -1170,13 +1168,11 @@ char *mingw_getcwd(char *pointer, int len)
1170
1168
return NULL ;
1171
1169
return pointer ;
1172
1170
}
1173
- if (!ret || ret >= ARRAY_SIZE (wpointer ))
1174
- return NULL ;
1175
- if (GetFileAttributesW (wpointer ) == INVALID_FILE_ATTRIBUTES ) {
1171
+ if (GetFileAttributesW (cwd ) == INVALID_FILE_ATTRIBUTES ) {
1176
1172
errno = ENOENT ;
1177
1173
return NULL ;
1178
1174
}
1179
- if (xwcstoutf (pointer , wpointer , len ) < 0 )
1175
+ if (xwcstoutf (pointer , cwd , len ) < 0 )
1180
1176
return NULL ;
1181
1177
convert_slashes (pointer );
1182
1178
return pointer ;
0 commit comments