From: Eric Blake <eblake@redhat.com>
Date: Fri, 8 Apr 2011 16:22:00 +0000 (-0600)
Subject: fcntl-h: fix O_ACCMODE on cygwin
X-Git-Tag: v0.1~2991
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=b277764ab1e0a68b1db0bf254ea4dbe8e16c0603;p=gnulib.git

fcntl-h: fix O_ACCMODE on cygwin

* doc/posix-headers/fcntl.texi (fcntl.h): Document the bug.
* lib/fcntl.in.h (O_ACCMODE): Fix it.

Signed-off-by: Eric Blake <eblake@redhat.com>
---

diff --git a/ChangeLog b/ChangeLog
index fe0a886391..58f0c53cad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-04-08  Eric Blake  <eblake@redhat.com>
 
+	fcntl-h: fix O_ACCMODE on cygwin
+	* doc/posix-headers/fcntl.texi (fcntl.h): Document the bug.
+	* lib/fcntl.in.h (O_ACCMODE): Fix it.
+
 	pipe-filter: drop O_NONBLOCK workarounds
 	* modules/pipe-filter-gi (Depends-on): Add fcntl-h.
 	* modules/pipe-filter-ii (Depends-on): Likewise.
diff --git a/doc/posix-headers/fcntl.texi b/doc/posix-headers/fcntl.texi
index 29b61ecb47..c87e8726d4 100644
--- a/doc/posix-headers/fcntl.texi
+++ b/doc/posix-headers/fcntl.texi
@@ -22,6 +22,11 @@ non-zero value; otherwise, the gnulib replacement is 0.
 @samp{O_EXEC} and @samp{O_SEARCH} are not defined on some platforms.
 Gnulib defines these macros to @samp{O_RDONLY}, which is typically 0.
 
+@item
+The @samp{O_ACCMODE} mask mistakenly omits @samp{O_SEARCH} and
+@samp{O_EXEC} on some platforms:
+Cygwin.
+
 @item
 @samp{O_BINARY}, @samp{O_TEXT} (not specified by POSIX, but essential for
 portability to Woe32 platforms) are defined on some platforms but not on
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index b6521d6719..971316fc05 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -256,6 +256,11 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
 # define O_TTY_INIT 0
 #endif
 
+#if O_ACCMODE != (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+# undef O_ACCMODE
+# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+#endif
+
 /* For systems that distinguish between text and binary I/O.
    O_BINARY is usually declared in fcntl.h  */
 #if !defined O_BINARY && defined _O_BINARY