bug-gnulib
[Top][All Lists]
Advanced

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

Re: getting EBADF on MSVC


From: Bruno Haible
Subject: Re: getting EBADF on MSVC
Date: Fri, 23 Sep 2011 20:57:27 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Paul Eggert wrote:
> > I'm not objecting to this MSVC stuff if it's put inside areas that are
> > "#ifdef _WIN32" or are otherwise clearly marked so that they are for
> > Windows only, and which the rest of us can safely ignore.  But the
> > style used in dup2.c is cluttering code that is otherwise perfectly
> > clear on mainstream (non-Windows) platforms.

Committing this fix:


2011-09-23  Bruno Haible  <address@hidden>

        dup2: Make code more maintainable.
        * lib/dup2.c (dup2_nothrow): New function, extracted from rpl_dup2.
        (rpl_dup2): Use it.
        * m4/dup2.m4 (gl_PREREQ_DUP2): New macro.
        * modules/dup2 (configure.ac): Invoke it.
        Reported by Paul Eggert.

--- lib/dup2.c.orig     Fri Sep 23 20:52:24 2011
+++ lib/dup2.c  Fri Sep 23 20:50:16 2011
@@ -37,6 +37,29 @@
 
 # undef dup2
 
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static inline int
+dup2_nothrow (int fd, int desired_fd)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = dup2 (fd, desired_fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+# else
+#  define dup2_nothrow dup2
+# endif
+
 int
 rpl_dup2 (int fd, int desired_fd)
 {
@@ -79,16 +102,7 @@
     return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
 # endif
 
-  TRY_MSVC_INVAL
-    {
-      result = dup2 (fd, desired_fd);
-    }
-  CATCH_MSVC_INVAL
-    {
-      result = -1;
-      errno = EBADF;
-    }
-  DONE_MSVC_INVAL;
+  result = dup2_nothrow (fd, desired_fd);
 
 # ifdef __linux__
   /* Correct a Linux return value.
--- m4/dup2.m4.orig     Fri Sep 23 20:52:24 2011
+++ m4/dup2.m4  Fri Sep 23 20:51:49 2011
@@ -1,4 +1,4 @@
-#serial 14
+#serial 15
 dnl Copyright (C) 2002, 2005, 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -71,3 +71,9 @@
     fi
   ])
 ])
+
+# Prerequisites of lib/dup2.c.
+AC_DEFUN([gl_PREREQ_DUP2].
+[
+  AC_REQUIRE([AC_C_INLINE])
+])
--- modules/dup2.orig   Fri Sep 23 20:52:24 2011
+++ modules/dup2        Fri Sep 23 20:51:56 2011
@@ -14,6 +14,7 @@
 gl_FUNC_DUP2
 if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then
   AC_LIBOBJ([dup2])
+  gl_PREREQ_DUP2
 fi
 gl_UNISTD_MODULE_INDICATOR([dup2])
 

-- 
In memoriam Ghazala Khan <http://en.wikipedia.org/wiki/Ghazala_Khan>



reply via email to

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