X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fdup2.c;h=7de6805499004d90ef56a0f255362d53152f6870;hb=25a6731afb775d2fe8ab53ea944158137d458462;hp=f6d0f1c73c5aa3c1fe4d7b66c933d553885df7f6;hpb=80a029602f5b2707ca8d2487843ecb9e0df74a6a;p=gnulib.git diff --git a/lib/dup2.c b/lib/dup2.c index f6d0f1c73..7de680549 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -1,6 +1,6 @@ /* Duplicate an open file descriptor to a specified file descriptor. - Copyright (C) 1999, 2004-2007, 2009-2012 Free Software Foundation, Inc. + Copyright (C) 1999, 2004-2007, 2009-2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -95,7 +95,14 @@ 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 Cygwin 1.7.25, dup2 (1, 256) can dump core. On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ +# if HAVE_SETDTABLESIZE + setdtablesize (desired_fd + 1); +# endif + if (desired_fd < 0) + fd = desired_fd; if (fd == desired_fd) return fcntl (fd, F_GETFL) == -1 ? -1 : fd; # endif