+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-06-03 Jim Meyering <meyering@redhat.com>
maint: three new prohibit-header-without-use rules
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.
#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. */
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;
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;
fcntl-h
binary-io
extensions
-nonblocking
+verify
configure.ac:
gl_FUNC_PIPE2
#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
#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;