ioctl: Fix test failure on native Windows.
authorBruno Haible <bruno@clisp.org>
Sat, 4 Feb 2012 15:39:30 +0000 (16:39 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 4 Feb 2012 15:39:30 +0000 (16:39 +0100)
* lib/ioctl.c: Include msvc-nothrow.h.
(primary_ioctl): If fd is not a valid handle, set errno to EBADF.

ChangeLog
lib/ioctl.c

index e7cd497..4bbe447 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2012-02-04  Bruno Haible  <bruno@clisp.org>
 
+       ioctl: Fix test failure on native Windows.
+       * lib/ioctl.c: Include msvc-nothrow.h.
+       (primary_ioctl): If fd is not a valid handle, set errno to EBADF.
+
+2012-02-04  Bruno Haible  <bruno@clisp.org>
+
        fsync: Avoid test failure on native Windows.
        * lib/fsync.c (fsync) [Windows]: Don't fail if the handle is merely
        read-only.
index 8701b7a..2e51c92 100644 (file)
@@ -47,6 +47,8 @@ rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
 # include <errno.h>
 
 # include "fd-hook.h"
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 
 static int
 primary_ioctl (int fd, int request, void *arg)
@@ -55,7 +57,10 @@ primary_ioctl (int fd, int request, void *arg)
      fds non-blocking, use the gnulib 'nonblocking' module, until
      gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
 
-  errno = ENOSYS;
+  if ((HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE)
+    errno = ENOSYS;
+  else
+    errno = EBADF;
   return -1;
 }