emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master facd6d5: Improve error reporting in file_accessible


From: Eli Zaretskii
Subject: [Emacs-diffs] master facd6d5: Improve error reporting in file_accessible_directory_p
Date: Mon, 16 Sep 2019 15:20:11 -0400 (EDT)

branch: master
commit facd6d5affaa897e7efe4018ede054489268b065
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Improve error reporting in file_accessible_directory_p
    
    * src/w32.c (w32_accessible_directory_p): Set errno, so that
    file_accessible_directory_p does on MS-Windows, to live up to
    its callers' expectations.
---
 src/w32.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/w32.c b/src/w32.c
index d7a9169..88e9aef 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -4151,13 +4151,36 @@ w32_accessible_directory_p (const char *dirname, 
ptrdiff_t dirlen)
       /* In case DIRNAME cannot be expressed in characters from the
         current ANSI codepage.  */
       if (_mbspbrk (pat_a, "?"))
-       dh = INVALID_HANDLE_VALUE;
-      else
-       dh = FindFirstFileA (pat_a, &dfd_a);
+       {
+         errno = ENOENT;
+         return 0;
+       }
+      dh = FindFirstFileA (pat_a, &dfd_a);
     }
 
   if (dh == INVALID_HANDLE_VALUE)
+    {
+      DWORD w32err = GetLastError ();
+
+      switch (w32err)
+       {
+       case ERROR_INVALID_NAME:
+       case ERROR_BAD_PATHNAME:
+       case ERROR_FILE_NOT_FOUND:
+       case ERROR_PATH_NOT_FOUND:
+       case ERROR_NO_MORE_FILES:
+       case ERROR_BAD_NETPATH:
+         errno = ENOENT;
+         break;
+       case ERROR_NOT_READY:
+         errno = ENODEV;
+         break;
+       default:
+         errno = EACCES;
+         break;
+       }
     return 0;
+    }
   FindClose (dh);
   return 1;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]