dup2: work around mingw bug
authorEric Blake <ebb9@byu.net>
Fri, 8 Jan 2010 15:17:00 +0000 (08:17 -0700)
committerEric Blake <ebb9@byu.net>
Fri, 8 Jan 2010 16:01:02 +0000 (09:01 -0700)
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>
ChangeLog
lib/dup2.c

index bd5565b..dc7776e 100644 (file)
--- 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.
index ef581a7..9b6a8f6 100644 (file)
@@ -52,6 +52,13 @@ rpl_dup2 (int fd, int desired_fd)
         }
       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__