]> git.eshelyaron.com Git - emacs.git/commitdiff
; * src/w32.c (sys_open): Set errno to EISDIR if opening a directory.
authorEli Zaretskii <eliz@gnu.org>
Wed, 29 May 2024 14:56:18 +0000 (17:56 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 29 May 2024 16:00:54 +0000 (18:00 +0200)
(cherry picked from commit 4e836407ce3a2140725c7ddc2cedc3478d34a479)

src/w32.c

index a1b34e4103bd1cd3af847b3b2b7386f18c1f06a0..6d0b178e9780263a9e525a10cf3eddadd6bf0d02 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -4652,6 +4652,14 @@ sys_open (const char * path, int oflag, int mode)
        res = _wopen (mpath_w, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
       if (res < 0)
        res = _wopen (mpath_w, oflag | _O_NOINHERIT, mode);
+      if (res < 0 && errno == EACCES)
+       {
+         DWORD attributes = GetFileAttributesW (mpath_w);
+
+         if (attributes != INVALID_FILE_ATTRIBUTES
+             && (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+           errno = EISDIR;
+       }
     }
   else
     {
@@ -4662,6 +4670,14 @@ sys_open (const char * path, int oflag, int mode)
        res = _open (mpath_a, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
       if (res < 0)
        res = _open (mpath_a, oflag | _O_NOINHERIT, mode);
+      if (res < 0 && errno == EACCES)
+       {
+         DWORD attributes = GetFileAttributesA (mpath_a);
+
+         if (attributes != INVALID_FILE_ATTRIBUTES
+             && (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+           errno = EISDIR;
+       }
     }
 
   return res;