nonblocking: fix mingw test failures
authorEric Blake <eblake@redhat.com>
Thu, 31 Mar 2011 21:28:37 +0000 (15:28 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 31 Mar 2011 21:28:37 +0000 (15:28 -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 <eblake@redhat.com>
ChangeLog
lib/nonblocking.c
modules/nonblocking-tests
tests/test-nonblocking.c

index c4687ce..9f58471 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-03-31  Eric Blake  <eblake@redhat.com>
+
+       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  <bruno@clisp.org>
 
        Fix bug with gl_WARN_ON_USE_PREPARE, introduced on 2011-01-23.
index cb103be..f28e423 100644 (file)
@@ -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;
     }
index 94fccb2..34d206d 100644 (file)
@@ -4,7 +4,6 @@ tests/macros.h
 
 Depends-on:
 close
-open
 pipe-posix
 socket
 
index 0762cd0..f1b7610 100644 (file)
@@ -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);