From 2cf2e370931afbad5ce4c365c3113008d90bcfef Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 8 Jan 2010 08:17:00 -0700 Subject: [PATCH] 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 --- ChangeLog | 6 ++++++ lib/dup2.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index bd5565b6f..dc7776eab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-01-08 Eric Blake + + 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 (tiny change) glob: Fix C++ compilation. diff --git a/lib/dup2.c b/lib/dup2.c index ef581a7ef..9b6a8f632 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -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__ -- 2.11.0