@@ -241,12 +241,16 @@ typedef struct {
241241 wchar_t * allocated ;
242242} win_path_t ;
243243
244+ static int is_windows_namespace_path (const wchar_t * path ) {
245+ return wcsncmp (path , L"\\\\?\\" , 4 ) == 0 ||
246+ wcsncmp (path , L"\\\\.\\" , 4 ) == 0 ||
247+ wcsncmp (path , L"\\??\\" , 4 ) == 0 ;
248+ }
249+
244250static int win_path_init (win_path_t * result , const wchar_t * path ) {
245251 result -> value = path ;
246252 result -> allocated = NULL ;
247- if (path [0 ] == L'\0' ||
248- (path [0 ] == L'\\' && path [1 ] == L'\\' && (path [2 ] == L'?' || path [2 ] == L'.' ) && path [3 ] == L'\\' ) ||
249- (path [0 ] == L'\\' && path [1 ] == L'?' && path [2 ] == L'?' && path [3 ] == L'\\' )) {
253+ if (path [0 ] == L'\0' || is_windows_namespace_path (path )) {
250254 return 0 ;
251255 }
252256
@@ -270,6 +274,7 @@ static int win_path_init(win_path_t *result, const wchar_t *path) {
270274 full_path = resized ;
271275 full_len = GetFullPathNameW (path , full_size , full_path , NULL );
272276 if (full_len == 0 ) {
277+ capture_errors ();
273278 free (full_path );
274279 // As above, preserve the error behavior of the actual filesystem operation.
275280 return 0 ;
@@ -290,7 +295,7 @@ static int win_path_init(win_path_t *result, const wchar_t *path) {
290295 return 0 ;
291296 }
292297
293- if (full_len >= 4 && full_path [ 0 ] == L'\\' && full_path [ 1 ] == L'\\' && full_path [ 2 ] == L'?' && full_path [ 3 ] == L'\\' ) {
298+ if (is_windows_namespace_path ( full_path ) ) {
294299 result -> value = full_path ;
295300 result -> allocated = full_path ;
296301 return 0 ;
0 commit comments