aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dup2.c
diff options
context:
space:
mode:
authorPaul Eggert2017-05-14 01:29:05 -0700
committerPaul Eggert2017-05-14 01:29:29 -0700
commit4132bd74e9816ca913f862835cc062e092ab8b79 (patch)
tree7861e23ef6007320ca0417a147656cf9774473b7 /lib/dup2.c
parent9a5e864de731e113badbe300b1e4174f103547fa (diff)
downloademacs-4132bd74e9816ca913f862835cc062e092ab8b79.tar.gz
emacs-4132bd74e9816ca913f862835cc062e092ab8b79.zip
Merge from gnulib
This incorporates: 2017-05-13 largefile: Simplify 2017-05-13 largefile: Improve and document 2017-05-13 truncate: New module 2017-05-13 windows-stat-timespec: New module 2017-05-13 windows-stat-override: New module 2017-05-11 getopt-posix: port to mingw 2017-05-11 gettimeofday: Increase precision on mingw 2017-05-10 time: Fix missing initialization of HAVE_TIMEZONE_T 2017-05-10 Implement a way to opt out from MSVC support 2017-05-09 tzset: Expand comment about TZ problem on native Windows * build-aux/config.guess, lib/dup2.c, lib/fcntl.c, lib/fsync.c: * lib/getdtablesize.c, lib/getopt.c, lib/gettimeofday.c: * lib/mktime.c, lib/stat-time.h, lib/sys_stat.in.h, lib/unistd.in.h: * lib/utimens.c, m4/gettimeofday.m4, m4/largefile.m4: * m4/sys_stat_h.m4, m4/sys_time_h.m4, m4/time_h.m4, m4/time_rz.m4: * m4/unistd_h.m4: Copy from gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib/dup2.c')
-rw-r--r--lib/dup2.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/lib/dup2.c b/lib/dup2.c
index c0c7cadf4a8..002dc8c76cb 100644
--- a/lib/dup2.c
+++ b/lib/dup2.c
@@ -35,10 +35,39 @@
35# define WIN32_LEAN_AND_MEAN 35# define WIN32_LEAN_AND_MEAN
36# include <windows.h> 36# include <windows.h>
37 37
38# include "msvc-inval.h" 38# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
39# include "msvc-inval.h"
40# endif
39 41
40/* Get _get_osfhandle. */ 42/* Get _get_osfhandle. */
41# include "msvc-nothrow.h" 43# if GNULIB_MSVC_NOTHROW
44# include "msvc-nothrow.h"
45# else
46# include <io.h>
47# endif
48
49# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
50static int
51dup2_nothrow (int fd, int desired_fd)
52{
53 int result;
54
55 TRY_MSVC_INVAL
56 {
57 result = dup2 (fd, desired_fd);
58 }
59 CATCH_MSVC_INVAL
60 {
61 errno = EBADF;
62 result = -1;
63 }
64 DONE_MSVC_INVAL;
65
66 return result;
67}
68# else
69# define dup2_nothrow dup2
70# endif
42 71
43static int 72static int
44ms_windows_dup2 (int fd, int desired_fd) 73ms_windows_dup2 (int fd, int desired_fd)
@@ -66,16 +95,7 @@ ms_windows_dup2 (int fd, int desired_fd)
66 return -1; 95 return -1;
67 } 96 }
68 97
69 TRY_MSVC_INVAL 98 result = dup2_nothrow (fd, desired_fd);
70 {
71 result = dup2 (fd, desired_fd);
72 }
73 CATCH_MSVC_INVAL
74 {
75 errno = EBADF;
76 result = -1;
77 }
78 DONE_MSVC_INVAL;
79 99
80 if (result == 0) 100 if (result == 0)
81 result = desired_fd; 101 result = desired_fd;