changeset 12605:c7910f932a31

dup2: work around mingw bug dup2 (fd, -2) returned -2 instead of the proper -1. * lib/dup2.c (rpl_dup2): Sanitize return value on mingw. Reported by Simon Josefsson. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Fri, 08 Jan 2010 08:17:00 -0700
parents cb14b3e81bd7
children 47c45341eca0
files ChangeLog lib/dup2.c
diffstat 2 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-01-08  Eric Blake  <ebb9@byu.net>
+
+	dup2: work around mingw bug
+	* lib/dup2.c (rpl_dup2): Sanitize return value on mingw.
+	Reported by Simon Josefsson.
+
 2010-01-07  John W. Eaton  <jwe@octave.org>  (tiny change)
 
 	glob: Fix C++ compilation.
--- a/lib/dup2.c
+++ b/lib/dup2.c
@@ -52,6 +52,13 @@
         }
       return fd;
     }
+  /* Some mingw versions also return the wrong value if desired_fd is
+     negative but not -1.  */
+  if (desired_fd < 0)
+    {
+      errno = EBADF;
+      return -1;
+    }
 # endif
   result = dup2 (fd, desired_fd);
 # ifdef __linux__