diff options
| author | Eli Zaretskii | 2015-01-28 19:42:28 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-01-28 19:42:28 +0200 |
| commit | ad588afdaa166bcdacbf9f746bd4d39b2c649768 (patch) | |
| tree | c3562982b7a711957cc43a87163e8ca791aa9dab /src/w32.c | |
| parent | ba10f4b56081d0f5069720c9ce0871e819b904f5 (diff) | |
| download | emacs-ad588afdaa166bcdacbf9f746bd4d39b2c649768.tar.gz emacs-ad588afdaa166bcdacbf9f746bd4d39b2c649768.zip | |
Improve the fix for bug #19701
src/dired.c (directory_files_internal, file_name_completion)
[WINDOWSNT]: Signal an error when errno is set non-zero by
'readdir', regardless of its value.
src/w32.c (sys_readdir): Set errno to ENOENT when the directory
doesn't exist and to EACCES when it's not accessible to the
current user. Set errno to zero when FindNextFile exhausts the
directory, so that callers don't interpret that as an error and
don't signal a file-error.
(open_unc_volume): Set errno to ENOENT if WNetOpenEnum fails.
Diffstat (limited to 'src/w32.c')
| -rw-r--r-- | src/w32.c | 41 |
1 files changed, 32 insertions, 9 deletions
| @@ -3433,17 +3433,30 @@ sys_readdir (DIR *dirp) | |||
| 3433 | 3433 | ||
| 3434 | if (dir_find_handle == INVALID_HANDLE_VALUE) | 3434 | if (dir_find_handle == INVALID_HANDLE_VALUE) |
| 3435 | { | 3435 | { |
| 3436 | /* Any changes in the value of errno here should be in sync | ||
| 3437 | with what directory_files_internal does when it calls | ||
| 3438 | readdir. */ | ||
| 3436 | switch (GetLastError ()) | 3439 | switch (GetLastError ()) |
| 3437 | { | 3440 | { |
| 3438 | case ERROR_PATH_NOT_FOUND: | 3441 | /* Windows uses this value when FindFirstFile finds no |
| 3442 | files that match the wildcard. This is not supposed | ||
| 3443 | to happen, since our wildcard is "*", but just in | ||
| 3444 | case, if there's some weird empty directory with not | ||
| 3445 | even "." and ".." entries... */ | ||
| 3446 | case ERROR_FILE_NOT_FOUND: | ||
| 3447 | errno = 0; | ||
| 3448 | /* FALLTHRU */ | ||
| 3449 | default: | ||
| 3450 | break; | ||
| 3439 | case ERROR_ACCESS_DENIED: | 3451 | case ERROR_ACCESS_DENIED: |
| 3452 | case ERROR_NETWORK_ACCESS_DENIED: | ||
| 3453 | errno = EACCES; | ||
| 3454 | break; | ||
| 3455 | case ERROR_PATH_NOT_FOUND: | ||
| 3440 | case ERROR_INVALID_DRIVE: | 3456 | case ERROR_INVALID_DRIVE: |
| 3441 | case ERROR_BAD_NETPATH: | 3457 | case ERROR_BAD_NETPATH: |
| 3442 | /* This special value will be noticed by | 3458 | case ERROR_BAD_NET_NAME: |
| 3443 | directory_files_internal, which see. */ | 3459 | errno = ENOENT; |
| 3444 | errno = ENOTDIR; | ||
| 3445 | break; | ||
| 3446 | default: | ||
| 3447 | break; | 3460 | break; |
| 3448 | } | 3461 | } |
| 3449 | return NULL; | 3462 | return NULL; |
| @@ -3452,12 +3465,18 @@ sys_readdir (DIR *dirp) | |||
| 3452 | else if (w32_unicode_filenames) | 3465 | else if (w32_unicode_filenames) |
| 3453 | { | 3466 | { |
| 3454 | if (!FindNextFileW (dir_find_handle, &dir_find_data_w)) | 3467 | if (!FindNextFileW (dir_find_handle, &dir_find_data_w)) |
| 3455 | return NULL; | 3468 | { |
| 3469 | errno = 0; | ||
| 3470 | return NULL; | ||
| 3471 | } | ||
| 3456 | } | 3472 | } |
| 3457 | else | 3473 | else |
| 3458 | { | 3474 | { |
| 3459 | if (!FindNextFileA (dir_find_handle, &dir_find_data_a)) | 3475 | if (!FindNextFileA (dir_find_handle, &dir_find_data_a)) |
| 3460 | return NULL; | 3476 | { |
| 3477 | errno = 0; | ||
| 3478 | return NULL; | ||
| 3479 | } | ||
| 3461 | } | 3480 | } |
| 3462 | 3481 | ||
| 3463 | /* Emacs never uses this value, so don't bother making it match | 3482 | /* Emacs never uses this value, so don't bother making it match |
| @@ -3559,7 +3578,11 @@ open_unc_volume (const char *path) | |||
| 3559 | if (result == NO_ERROR) | 3578 | if (result == NO_ERROR) |
| 3560 | return henum; | 3579 | return henum; |
| 3561 | else | 3580 | else |
| 3562 | return INVALID_HANDLE_VALUE; | 3581 | { |
| 3582 | /* Make sure directory_files_internal reports a sensible error. */ | ||
| 3583 | errno = ENOENT; | ||
| 3584 | return INVALID_HANDLE_VALUE; | ||
| 3585 | } | ||
| 3563 | } | 3586 | } |
| 3564 | 3587 | ||
| 3565 | static void * | 3588 | static void * |