Revert "Update gnulib to current upstream master"
[external/binutils.git] / gdb / gnulib / import / dup2.c
index c7d1767..5d026f2 100644 (file)
@@ -1,6 +1,6 @@
 /* Duplicate an open file descriptor to a specified file descriptor.
 
-   Copyright (C) 1999, 2004-2007, 2009-2018 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2004-2007, 2009-2016 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
@@ -13,7 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* written by Paul Eggert */
 
 
 # undef dup2
 
-# if defined _WIN32 && ! defined __CYGWIN__
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
 /* Get declarations of the native Windows API functions.  */
 #  define WIN32_LEAN_AND_MEAN
 #  include <windows.h>
 
-#  if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-#   include "msvc-inval.h"
-#  endif
+#  include "msvc-inval.h"
 
 /* Get _get_osfhandle.  */
-#  if GNULIB_MSVC_NOTHROW
-#   include "msvc-nothrow.h"
-#  else
-#   include <io.h>
-#  endif
-
-#  if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-dup2_nothrow (int fd, int desired_fd)
-{
-  int result;
-
-  TRY_MSVC_INVAL
-    {
-      result = dup2 (fd, desired_fd);
-    }
-  CATCH_MSVC_INVAL
-    {
-      errno = EBADF;
-      result = -1;
-    }
-  DONE_MSVC_INVAL;
-
-  return result;
-}
-#  else
-#   define dup2_nothrow dup2
-#  endif
+#  include "msvc-nothrow.h"
 
 static int
 ms_windows_dup2 (int fd, int desired_fd)
@@ -88,14 +59,23 @@ ms_windows_dup2 (int fd, int desired_fd)
     }
 
   /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
-     https://bugs.winehq.org/show_bug.cgi?id=21289 */
+     http://bugs.winehq.org/show_bug.cgi?id=21289 */
   if (desired_fd < 0)
     {
       errno = EBADF;
       return -1;
     }
 
-  result = dup2_nothrow (fd, desired_fd);
+  TRY_MSVC_INVAL
+    {
+      result = dup2 (fd, desired_fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      errno = EBADF;
+      result = -1;
+    }
+  DONE_MSVC_INVAL;
 
   if (result == 0)
     result = desired_fd;