X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fdup3.c;h=307318932fd26c1a76dcd82a8710d2b23a1d35c2;hb=e7086a9a301ffcfef17edbcba9e7c0312c33f7a8;hp=5ae8b44ea860aea4c9d57f0fdddf46f0225c9df8;hpb=ffb0b29997c66526985e1f4a496335d0ab4ef111;p=gnulib.git
diff --git a/lib/dup3.c b/lib/dup3.c
index 5ae8b44ea..307318932 100644
--- a/lib/dup3.c
+++ b/lib/dup3.c
@@ -1,5 +1,5 @@
/* Copy a file descriptor, applying specific flags.
- Copyright (C) 2009-2010 Free Software Foundation, Inc.
+ Copyright (C) 2009-2013 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
@@ -12,8 +12,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ with this program; if not, see . */
#include
@@ -26,25 +25,15 @@
#include "binary-io.h"
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Native Woe32 API. */
-
-# include
-
-/* Get declarations of the Win32 API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include
-
-/* Upper bound on getdtablesize(). See lib/getdtablesize.c. */
-# define OPEN_MAX_MAX 0x10000
-
-#endif
-
int
dup3 (int oldfd, int newfd, int flags)
{
#if HAVE_DUP3
# undef dup3
+# if HAVE_SETDTABLESIZE
+ /* Avoid a cygwin crasher. */
+ setdtablesize (newfd + 1);
+# endif
/* Try the system call first, if it exists. (We may be running with a glibc
that has the function but with an older kernel that lacks it.) */
{
@@ -56,10 +45,10 @@ dup3 (int oldfd, int newfd, int flags)
if (!(result < 0 && errno == ENOSYS))
{
have_dup3_really = 1;
-#if REPLACE_FCHDIR
+# if REPLACE_FCHDIR
if (0 <= result)
result = _gl_register_dup (oldfd, newfd);
-#endif
+# endif
return result;
}
have_dup3_really = -1;
@@ -107,9 +96,9 @@ dup3 (int oldfd, int newfd, int flags)
#if O_BINARY
if (flags & O_BINARY)
- setmode (newfd, O_BINARY);
+ set_binary_mode (newfd, O_BINARY);
else if (flags & O_TEXT)
- setmode (newfd, O_TEXT);
+ set_binary_mode (newfd, O_TEXT);
#endif
return newfd;