pipe2: Remove dependency on 'nonblocking' module.
authorBruno Haible <bruno@clisp.org>
Thu, 2 Jun 2011 22:10:00 +0000 (00:10 +0200)
committerIan Beckwith <ianb@erislabs.net>
Thu, 9 Jun 2011 23:30:46 +0000 (00:30 +0100)
* lib/pipe2.c: Include verify.h. Include nonblocking.h only if
O_NONBLOCK is defined by gnulib.
(pipe2) [WIN32]: If O_NONBLOCK is not defined by gnulib, verify that it
is zero.
* modules/pipe2 (Depends-on): Add verify. Remove nonblocking.
* tests/test-pipe2.c: Include nonblocking.h only if O_NONBLOCK is
defined by gnulib.
(get_nonblocking_flag): New function.
(main): Test O_NONBLOCK flag only if it is nonzero.
(cherry picked from commit 64e338384bc99dfb49c4f46648b3fa0c50e8491d)

ChangeLog
doc/glibc-functions/pipe2.texi
lib/pipe2.c
modules/pipe2
tests/test-pipe2.c

index 1114ec9..6c28b02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-06-02  Bruno Haible  <bruno@clisp.org>
+
+       pipe2: Remove dependency on 'nonblocking' module.
+       * lib/pipe2.c: Include verify.h. Include nonblocking.h only if
+       O_NONBLOCK is defined by gnulib.
+       (pipe2) [WIN32]: If O_NONBLOCK is not defined by gnulib, verify that it
+       is zero.
+       * modules/pipe2 (Depends-on): Add verify. Remove nonblocking.
+       * tests/test-pipe2.c: Include nonblocking.h only if O_NONBLOCK is
+       defined by gnulib.
+       (get_nonblocking_flag): New function.
+       (main): Test O_NONBLOCK flag only if it is nonzero.
+       * doc/glibc-functions/pipe2.texi: Mention the 'nonblocking' module.
+
 2011-05-31  Bruno Haible  <bruno@clisp.org>
 
        Fix link errors in tests: openat-die uses gettext-h.
index f33d90d..5721ae9 100644 (file)
@@ -15,3 +15,6 @@ IRIX 6.5, OSF/1 5.1, Solaris 11 2010-11, Cygwin 1.7.1, mingw, Interix 3.5, BeOS.
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
+
+Note: This function portably supports the @code{O_NONBLOCK} flag only if the
+gnulib module @code{nonblocking} is also used.
index 18098c4..f50dae6 100644 (file)
 #include <fcntl.h>
 
 #include "binary-io.h"
-#include "nonblocking.h"
+#include "verify.h"
+
+#if GNULIB_defined_O_NONBLOCK
+# include "nonblocking.h"
+#endif
 
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 /* Native Woe32 API.  */
@@ -69,12 +73,19 @@ pipe2 (int fd[2], int flags)
   if (_pipe (fd, 4096, flags & ~O_NONBLOCK) < 0)
     return -1;
 
+  /* O_NONBLOCK handling.
+     On native Windows platforms, O_NONBLOCK is defined by gnulib.  Use the
+     functions defined by the gnulib module 'nonblocking'.  */
+# if GNULIB_defined_O_NONBLOCK
   if (flags & O_NONBLOCK)
     {
       if (set_nonblocking_flag (fd[0], true) != 0
           || set_nonblocking_flag (fd[1], true) != 0)
         goto fail;
     }
+# else
+  verify (O_NONBLOCK == 0);
+# endif
 
   return 0;
 
@@ -88,6 +99,8 @@ pipe2 (int fd[2], int flags)
      says that initially, the O_NONBLOCK and FD_CLOEXEC flags are cleared on
      both fd[0] and fd[1].  */
 
+  /* O_NONBLOCK handling.
+     On Unix platforms, O_NONBLOCK is defined by the system.  Use fcntl().  */
   if (flags & O_NONBLOCK)
     {
       int fcntl_flags;
index ca72216..62872a2 100644 (file)
@@ -10,7 +10,7 @@ unistd
 fcntl-h
 binary-io
 extensions
-nonblocking
+verify
 
 configure.ac:
 gl_FUNC_PIPE2
index 8ca8e01..d83162c 100644 (file)
@@ -33,7 +33,9 @@ SIGNATURE_CHECK (pipe2, int, (int[2], int));
 
 #include "binary-io.h"
 #include "macros.h"
-#include "nonblocking.h"
+#if GNULIB_NONBLOCKING
+# include "nonblocking.h"
+#endif
 
 /* Return true if FD is open.  */
 static bool
@@ -68,13 +70,30 @@ is_cloexec (int fd)
 #endif
 }
 
+#if ! GNULIB_NONBLOCKING
+static int
+get_nonblocking_flag (int fd)
+{
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  return 0;
+# else
+#  ifndef F_GETFL
+#   error Please port fcntl to your platform
+#  endif
+  int flags;
+  ASSERT ((flags = fcntl (fd, F_GETFL)) >= 0);
+  return (flags & O_NONBLOCK) != 0;
+# endif
+}
+#endif
+
 int
 main ()
 {
   int use_nonblocking;
   int use_cloexec;
 
-  for (use_nonblocking = 0; use_nonblocking <= 1; use_nonblocking++)
+  for (use_nonblocking = 0; use_nonblocking <= !!O_NONBLOCK; use_nonblocking++)
     for (use_cloexec = 0; use_cloexec <= !!O_CLOEXEC; use_cloexec++)
       {
         int o_flags;