bug-gnulib
[Top][All Lists]
Advanced

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

Re: errno from open(<directory>) ?


From: Gisle Vanem
Subject: Re: errno from open(<directory>) ?
Date: Mon, 22 May 2017 14:04:58 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

Tim Rühsen wrote:

Built on MinGW / Win32 the same open sets errno to EACCES.


We currently use a work-around like
+       int rc = open(pathname, flags, mode);
+#ifdef _WIN32
+       if (rc < 0 && errno == EACCES) {
+               DWORD attrs = GetFileAttributes(pathname);
+               if (attrs & FILE_ATTRIBUTE_DIRECTORY)
+                       errno = EISDIR;
+       }
+#endif

MSDN says:
  If the function fails, the return value is INVALID_FILE_ATTRIBUTES.

which is ((DWORD)-1). So the test should better be:

  if (attr != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
    errno = EISDIR;

--
--gv



reply via email to

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