]> code.delx.au - gnu-emacs/blobdiff - src/w32.c
Merge from origin/emacs-24
[gnu-emacs] / src / w32.c
index 31b13289b575e738715ce2ce393113cde7eb6240..547db0f6dd93fb7af1c57de4285fb651838cad78 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -3433,17 +3433,52 @@ sys_readdir (DIR *dirp)
        }
 
       if (dir_find_handle == INVALID_HANDLE_VALUE)
-       return NULL;
+       {
+         /* Any changes in the value of errno here should be in sync
+            with what directory_files_internal does when it calls
+            readdir.  */
+         switch (GetLastError ())
+           {
+             /* Windows uses this value when FindFirstFile finds no
+                files that match the wildcard.  This is not supposed
+                to happen, since our wildcard is "*", but just in
+                case, if there's some weird empty directory with not
+                even "." and ".." entries...  */
+           case ERROR_FILE_NOT_FOUND:
+             errno = 0;
+             /* FALLTHRU */
+           default:
+             break;
+           case ERROR_ACCESS_DENIED:
+           case ERROR_NETWORK_ACCESS_DENIED:
+             errno = EACCES;
+             break;
+           case ERROR_PATH_NOT_FOUND:
+           case ERROR_INVALID_DRIVE:
+           case ERROR_NOT_READY:
+           case ERROR_BAD_NETPATH:
+           case ERROR_BAD_NET_NAME:
+             errno = ENOENT;
+             break;
+           }
+         return NULL;
+       }
     }
   else if (w32_unicode_filenames)
     {
       if (!FindNextFileW (dir_find_handle, &dir_find_data_w))
-       return NULL;
+       {
+         errno = 0;
+         return NULL;
+       }
     }
   else
     {
       if (!FindNextFileA (dir_find_handle, &dir_find_data_a))
-       return NULL;
+       {
+         errno = 0;
+         return NULL;
+       }
     }
 
   /* Emacs never uses this value, so don't bother making it match
@@ -3545,7 +3580,11 @@ open_unc_volume (const char *path)
   if (result == NO_ERROR)
     return henum;
   else
-    return INVALID_HANDLE_VALUE;
+    {
+      /* Make sure directory_files_internal reports a sensible error.  */
+      errno = ENOENT;
+      return INVALID_HANDLE_VALUE;
+    }
 }
 
 static void *