Changeset 1964 for cpio/vendor/current/gnu/dup2.c
- Timestamp:
- Feb 3, 2017, 2:02:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified cpio/vendor/current/gnu/dup2.c ¶
r118 r1964 1 /* -*- buffer-read-only: t -*- vi: set ro: */2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */3 1 /* Duplicate an open file descriptor to a specified file descriptor. 4 2 5 Copyright (C) 1999, 2004-2007, 2009-201 0Free Software Foundation, Inc.3 Copyright (C) 1999, 2004-2007, 2009-2015 Free Software Foundation, Inc. 6 4 7 5 This program is free software: you can redistribute it and/or modify … … 28 26 #include <fcntl.h> 29 27 30 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__31 /* Get declarations of the Win32 API functions. */32 # define WIN32_LEAN_AND_MEAN33 # include <windows.h>34 #endif35 36 28 #if HAVE_DUP2 37 29 38 30 # undef dup2 39 31 40 int 41 rpl_dup2 (int fd, int desired_fd) 32 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 33 34 /* Get declarations of the native Windows API functions. */ 35 # define WIN32_LEAN_AND_MEAN 36 # include <windows.h> 37 38 # include "msvc-inval.h" 39 40 /* Get _get_osfhandle. */ 41 # include "msvc-nothrow.h" 42 43 static int 44 ms_windows_dup2 (int fd, int desired_fd) 42 45 { 43 46 int result; 44 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 47 45 48 /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open, 46 49 dup2 (fd, fd) returns 0, but all further attempts to use fd in … … 55 58 return fd; 56 59 } 60 57 61 /* Wine 1.0.1 return 0 when desired_fd is negative but not -1: 58 62 http://bugs.winehq.org/show_bug.cgi?id=21289 */ … … 62 66 return -1; 63 67 } 64 # endif 65 result = dup2 (fd, desired_fd); 66 # ifdef __linux__ 67 /* Correct a Linux return value. 68 <http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.30.y.git;a=commitdiff;h=2b79bc4f7ebbd5af3c8b867968f9f15602d5f802> 69 */ 70 if (fd == desired_fd && result == (unsigned int) -EBADF) 68 69 TRY_MSVC_INVAL 70 { 71 result = dup2 (fd, desired_fd); 72 } 73 CATCH_MSVC_INVAL 71 74 { 72 75 errno = EBADF; 73 76 result = -1; 74 77 } 75 # endif 78 DONE_MSVC_INVAL; 79 76 80 if (result == 0) 77 81 result = desired_fd; 78 /* Correct a cygwin 1.5.x errno value. */ 79 else if (result == -1 && errno == EMFILE) 82 83 return result; 84 } 85 86 # define dup2 ms_windows_dup2 87 88 # endif 89 90 int 91 rpl_dup2 (int fd, int desired_fd) 92 { 93 int result; 94 95 # ifdef F_GETFL 96 /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. 97 On Cygwin 1.5.x, dup2 (1, 1) returns 0. 98 On Cygwin 1.7.17, dup2 (1, -1) dumps core. 99 On Cygwin 1.7.25, dup2 (1, 256) can dump core. 100 On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ 101 # if HAVE_SETDTABLESIZE 102 setdtablesize (desired_fd + 1); 103 # endif 104 if (desired_fd < 0) 105 fd = desired_fd; 106 if (fd == desired_fd) 107 return fcntl (fd, F_GETFL) == -1 ? -1 : fd; 108 # endif 109 110 result = dup2 (fd, desired_fd); 111 112 /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */ 113 if (result == -1 && errno == EMFILE) 80 114 errno = EBADF; 81 115 # if REPLACE_FCHDIR
Note:
See TracChangeset
for help on using the changeset viewer.