From 1d0ee3d8f5b45a7af49fd76aa8bdc2b698ecb9c6 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 29 May 2024 17:56:18 +0300 Subject: [PATCH] ; * src/w32.c (sys_open): Set errno to EISDIR if opening a directory. (cherry picked from commit 4e836407ce3a2140725c7ddc2cedc3478d34a479) --- src/w32.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/w32.c b/src/w32.c index a1b34e4103b..6d0b178e978 100644 --- 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; -- 2.39.2