bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] nonblocking: fix mingw test failures


From: Eric Blake
Subject: [PATCH] nonblocking: fix mingw test failures
Date: Thu, 31 Mar 2011 15:40:30 -0600

Actually testing on mingw uncovered a few more problems.

* lib/nonblocking.c (set_nonblocking_flag): Succeed when clearing
non-blocking flag on regular file.
(get_nonblocking_flag): Set errno on invalid fd.
* tests/test-nonblocking.c (main): Avoid test failure on
directories if fchdir is not active.
* modules/nonblocking-tests (Depends-on): Drop unused dependency.

Signed-off-by: Eric Blake <address@hidden>
---

When run at speed, this passes.  But when run under cygwin's gdb, the
program crashes on _close(fd) inside sockets.c:close_fd_maybe_socket.
Something gdb does makes windows revert to its behavior of having
_close throw an exception instead of returning EBADF; it probably
has something to do with the invalid parameter handler.

 ChangeLog                 |   10 ++++++++++
 lib/nonblocking.c         |   13 +++++++++++++
 modules/nonblocking-tests |    1 -
 tests/test-nonblocking.c  |   13 ++++++++-----
 4 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c4687ce..9f58471 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-03-31  Eric Blake  <address@hidden>
+
+       nonblocking: fix mingw test failures
+       * lib/nonblocking.c (set_nonblocking_flag): Succeed when clearing
+       non-blocking flag on regular file.
+       (get_nonblocking_flag): Set errno on invalid fd.
+       * tests/test-nonblocking.c (main): Avoid test failure on
+       directories if fchdir is not active.
+       * modules/nonblocking-tests (Depends-on): Drop unused dependency.
+
 2011-03-31  Bruno Haible  <address@hidden>

        Fix bug with gl_WARN_ON_USE_PREPARE, introduced on 2011-01-23.
diff --git a/lib/nonblocking.c b/lib/nonblocking.c
index cb103be..f28e423 100644
--- a/lib/nonblocking.c
+++ b/lib/nonblocking.c
@@ -24,6 +24,7 @@
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 /* Native Woe32 API.  */

+# include <sys/ioctl.h>
 # include <sys/socket.h>
 # include <unistd.h>

@@ -35,6 +36,11 @@ int
 get_nonblocking_flag (int desc)
 {
   HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
   if (GetFileType (h) == FILE_TYPE_PIPE)
     {
       /* h is a pipe or socket.  */
@@ -56,6 +62,11 @@ int
 set_nonblocking_flag (int desc, bool value)
 {
   HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
   if (GetFileType (h) == FILE_TYPE_PIPE)
     {
       /* h is a pipe or socket.  */
@@ -90,6 +101,8 @@ set_nonblocking_flag (int desc, bool value)
   else
     {
       /* Win32 does not support non-blocking on regular files.  */
+      if (!value)
+        return 0;
       errno = ENOTSUP;
       return -1;
     }
diff --git a/modules/nonblocking-tests b/modules/nonblocking-tests
index 94fccb2..34d206d 100644
--- a/modules/nonblocking-tests
+++ b/modules/nonblocking-tests
@@ -4,7 +4,6 @@ tests/macros.h

 Depends-on:
 close
-open
 pipe-posix
 socket

diff --git a/tests/test-nonblocking.c b/tests/test-nonblocking.c
index 0762cd0..f1b7610 100644
--- a/tests/test-nonblocking.c
+++ b/tests/test-nonblocking.c
@@ -55,11 +55,14 @@ main (void)

   /* Test directories; setting nonblocking is unspecified.  */
   fd_file = open (".", O_RDONLY);
-  ASSERT (STDERR_FILENO < fd_file);
-  ASSERT (get_nonblocking_flag (fd_file) == 0);
-  ASSERT (set_nonblocking_flag (fd_file, false) == 0);
-  ASSERT (get_nonblocking_flag (fd_file) == 0);
-  ASSERT (close (fd_file) == 0);
+  if (STDERR_FILENO < fd_file)
+    {
+      /* mingw can't open directories unless fchdir module is active.  */
+      ASSERT (get_nonblocking_flag (fd_file) == 0);
+      ASSERT (set_nonblocking_flag (fd_file, false) == 0);
+      ASSERT (get_nonblocking_flag (fd_file) == 0);
+      ASSERT (close (fd_file) == 0);
+    }

   /* Test pipes.  */
   ASSERT (pipe (fd_pipe) == 0);
-- 
1.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]