From: Bruno Haible Date: Thu, 2 Jun 2011 22:10:00 +0000 (+0200) Subject: pipe2: Remove dependency on 'nonblocking' module. X-Git-Tag: stable/20110609~38 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=e54b6161486475d120c0a37a55518eba9dbb228c 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. (cherry picked from commit 64e338384bc99dfb49c4f46648b3fa0c50e8491d) --- diff --git a/ChangeLog b/ChangeLog index 1114ec9ab..6c28b0263 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-06-02 Bruno Haible + + 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 Fix link errors in tests: openat-die uses gettext-h. diff --git a/doc/glibc-functions/pipe2.texi b/doc/glibc-functions/pipe2.texi index f33d90d48..5721ae9b9 100644 --- a/doc/glibc-functions/pipe2.texi +++ b/doc/glibc-functions/pipe2.texi @@ -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. diff --git a/lib/pipe2.c b/lib/pipe2.c index 18098c4b4..f50dae665 100644 --- a/lib/pipe2.c +++ b/lib/pipe2.c @@ -24,7 +24,11 @@ #include #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; diff --git a/modules/pipe2 b/modules/pipe2 index ca722168a..62872a225 100644 --- a/modules/pipe2 +++ b/modules/pipe2 @@ -10,7 +10,7 @@ unistd fcntl-h binary-io extensions -nonblocking +verify configure.ac: gl_FUNC_PIPE2 diff --git a/tests/test-pipe2.c b/tests/test-pipe2.c index 8ca8e0136..d83162c2f 100644 --- a/tests/test-pipe2.c +++ b/tests/test-pipe2.c @@ -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;