projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
dup2, dup3: work around another cygwin crasher
[gnulib.git]
/
lib
/
dup2.c
diff --git
a/lib/dup2.c
b/lib/dup2.c
index
278261f
..
f128e7a
100644
(file)
--- a/
lib/dup2.c
+++ b/
lib/dup2.c
@@
-1,6
+1,6
@@
/* Duplicate an open file descriptor to a specified file descriptor.
/* Duplicate an open file descriptor to a specified file descriptor.
- Copyright (C) 1999, 2004-2007, 2009-201
1
Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004-2007, 2009-201
3
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
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
@@
-31,7
+31,7
@@
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Get declarations of the
Win32
API functions. */
+/* Get declarations of the
native Windows
API functions. */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
@@
-40,7
+40,7
@@
/* Get _get_osfhandle. */
# include "msvc-nothrow.h"
/* Get _get_osfhandle. */
# include "msvc-nothrow.h"
-static in
line in
t
+static int
ms_windows_dup2 (int fd, int desired_fd)
{
int result;
ms_windows_dup2 (int fd, int desired_fd)
{
int result;
@@
-92,10
+92,17
@@
rpl_dup2 (int fd, int desired_fd)
{
int result;
{
int result;
-# if
!((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# if
def 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 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. */
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
if (fd == desired_fd)
return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
# endif