[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 4/4] pipe2: fix O_NONBLOCK support on mingw
From: |
Bruno Haible |
Subject: |
Re: [PATCH 4/4] pipe2: fix O_NONBLOCK support on mingw |
Date: |
Fri, 3 Jun 2011 00:15:47 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote on 2011-04-08:
> * modules/pipe2 (Depends-on): Add nonblocking.
> * lib/pipe2.c (pipe2) [WIN32]: Add O_NONBLOCK support.
> * tests/test-pipe2.c (is_nonblocking): Adjust test accordingly.
This dependency is not warranted and causes trouble in gettext.
It's not warranted, because if someone calls pipe2() without the O_NONBLOCK
flag, no non-blocking support is needed in stdio.
It causes trouble in gettext, because the 'nonblocking' module leads to an
inclusion of lib/stdio-read.c, and AC_LIBOBJ is used from the wrong place.
This will be fixed later.
2011-06-02 Bruno Haible <address@hidden>
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.
--- lib/pipe2.c.orig Fri Jun 3 00:06:07 2011
+++ lib/pipe2.c Fri Jun 3 00:02:53 2011
@@ -24,7 +24,11 @@
#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 @@
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 @@
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;
--- modules/pipe2.orig Fri Jun 3 00:06:07 2011
+++ modules/pipe2 Fri Jun 3 00:02:59 2011
@@ -10,7 +10,7 @@
fcntl-h
binary-io
extensions
-nonblocking
+verify
configure.ac:
gl_FUNC_PIPE2
--- tests/test-pipe2.c.orig Fri Jun 3 00:06:08 2011
+++ tests/test-pipe2.c Thu Jun 2 23:55:17 2011
@@ -33,7 +33,9 @@
#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 @@
#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;
--
In memoriam Viktor Popkov <http://en.wikipedia.org/wiki/Viktor_Popkov>
- Re: [PATCH 4/4] pipe2: fix O_NONBLOCK support on mingw,
Bruno Haible <=