gettimeofday: port recent C++ fix to Emacs
[gnulib.git] / lib / ioctl.c
index 8701b7a..cd25911 100644 (file)
@@ -1,6 +1,6 @@
 /* ioctl.c --- wrappers for Windows ioctl function
 
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   Copyright (C) 2008-2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -46,7 +46,13 @@ rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
 
 # include <errno.h>
 
+/* Get HANDLE.  */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
 # include "fd-hook.h"
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 
 static int
 primary_ioctl (int fd, int request, void *arg)
@@ -55,7 +61,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;
 }