diff options
author | Eric Blake <eblake@redhat.com> | 2012-12-31 11:15:53 -0700 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2012-12-31 11:51:32 -0700 |
commit | cb83c6cb603abfa9cd8945013226e17c894309f2 (patch) | |
tree | 4996d34a82ed3f0798f243cfc801ef92c0060439 /lib/dup2.c | |
parent | 14ec011a3937faee6f4af6ea1655fffdf5691576 (diff) | |
download | gnulib-cb83c6cb603abfa9cd8945013226e17c894309f2.tar.gz |
dup2: work around cygwin bug
Detected by './gnulib-tool --test dup2 cloexec'.
Reported upstream: http://cygwin.com/ml/cygwin/2012-12/msg00377.html
and fixed already: http://cygwin.com/ml/cygwin-cvs/2012-q4/msg00202.html
but as we want to work with older cygwin, we'll have to carry this
in gnulib for a while.
* m4/dup2.m4 (gl_FUNC_DUP2): Flush out cygwin core dump.
* lib/dup2.c (rpl_dup2): Work around it.
* doc/posix-functions/dup2.texi (dup2): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'lib/dup2.c')
-rw-r--r-- | lib/dup2.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/dup2.c b/lib/dup2.c index f6d0f1c73c..36b3399067 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -95,7 +95,10 @@ rpl_dup2 (int fd, int desired_fd) # ifdef F_GETFL /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. On Cygwin 1.5.x, dup2 (1, 1) returns 0. + On Cygwin 1.7.17, dup2 (1, -1) dumps core. On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ + if (desired_fd < 0) + fd = desired_fd; if (fd == desired_fd) return fcntl (fd, F_GETFL) == -1 ? -1 : fd; # endif |