Mercurial > gnulib
annotate tests/test-fcntl.c @ 39221:f2c01d874a71
Avoid test failures on Microsoft Windows Subsystem for Linux.
* tests/test-fcntl.c (main): Allow a different errno.
* tests/test-rename.h (test_rename): Likewise.
* tests/test-renameat.c (main): Likewise.
* tests/test-renameat2.c (main): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 22 Jan 2018 05:01:48 +0100 |
parents | 24e347e0e326 |
children | beb2ad957aca |
rev | line source |
---|---|
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* Test of fcntl(2). |
39199
24e347e0e326
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
38844
diff
changeset
|
2 Copyright (C) 2009-2018 Free Software Foundation, Inc. |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
3 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
7 (at your option) any later version. |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
8 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
13 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
38844 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
16 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
18 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
19 #include <config.h> |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
20 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
21 /* Specification. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
22 #include <fcntl.h> |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
23 |
32180 | 24 #include "signature.h" |
25 SIGNATURE_CHECK (fcntl, int, (int, int, ...)); | |
26 | |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
27 /* Helpers. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
28 #include <errno.h> |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
29 #include <stdarg.h> |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
30 #include <stdbool.h> |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
31 #include <unistd.h> |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
33 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
35905
ca0078f28044
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
35892
diff
changeset
|
34 /* Get declarations of the native Windows API functions. */ |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
35 # define WIN32_LEAN_AND_MEAN |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
36 # include <windows.h> |
35443
81f93aab9044
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
35400
diff
changeset
|
37 /* Get _get_osfhandle. */ |
38562
4e054cafa4f4
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
38305
diff
changeset
|
38 # if GNULIB_MSVC_NOTHROW |
4e054cafa4f4
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
38305
diff
changeset
|
39 # include "msvc-nothrow.h" |
4e054cafa4f4
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
38305
diff
changeset
|
40 # else |
4e054cafa4f4
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
38305
diff
changeset
|
41 # include <io.h> |
4e054cafa4f4
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
38305
diff
changeset
|
42 # endif |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
43 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
44 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
45 #include "binary-io.h" |
32187
25173b78d540
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
32180
diff
changeset
|
46 #include "macros.h" |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
47 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
48 #if !O_BINARY |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
49 # define setmode(f,m) zero () |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
50 static int zero (void) { return 0; } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
51 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
52 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
53 /* Return true if FD is open. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
54 static bool |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
55 is_open (int fd) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
56 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
57 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
35905
ca0078f28044
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
35892
diff
changeset
|
58 /* On native Windows, the initial state of unassigned standard file |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
59 descriptors is that they are open but point to an |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
60 INVALID_HANDLE_VALUE, and there is no fcntl. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
61 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
62 #else |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
63 # ifndef F_GETFL |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
64 # error Please port fcntl to your platform |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
65 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
66 return 0 <= fcntl (fd, F_GETFL); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
67 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
68 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
69 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
70 /* Return true if FD is open and inheritable across exec/spawn. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
71 static bool |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
72 is_inheritable (int fd) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
73 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
35905
ca0078f28044
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
35892
diff
changeset
|
75 /* On native Windows, the initial state of unassigned standard file |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 descriptors is that they are open but point to an |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 INVALID_HANDLE_VALUE, and there is no fcntl. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
78 HANDLE h = (HANDLE) _get_osfhandle (fd); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
79 DWORD flags; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
80 if (h == INVALID_HANDLE_VALUE || GetHandleInformation (h, &flags) == 0) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
81 return false; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
82 return (flags & HANDLE_FLAG_INHERIT) != 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
83 #else |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
84 # ifndef F_GETFD |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
85 # error Please port fcntl to your platform |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
86 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
87 int i = fcntl (fd, F_GETFD); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
88 return 0 <= i && (i & FD_CLOEXEC) == 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
89 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
90 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
91 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
92 /* Return non-zero if FD is open in the given MODE, which is either |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
93 O_TEXT or O_BINARY. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
94 static bool |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
95 is_mode (int fd, int mode) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
96 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
97 int value = setmode (fd, O_BINARY); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
98 setmode (fd, value); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
99 return mode == value; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
100 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
101 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
102 /* Since native fcntl can have more supported operations than our |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
103 replacement is aware of, and since various operations assign |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
104 different types to the vararg argument, a wrapper around fcntl must |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
105 be able to pass a vararg of unknown type on through to the original |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
106 fcntl. Make sure that this works properly: func1 behaves like the |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
107 original fcntl interpreting the vararg as an int or a pointer to a |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
108 struct, and func2 behaves like rpl_fcntl that doesn't know what |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
109 type to forward. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
110 struct dummy_struct |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
111 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
112 long filler; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
113 int value; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
114 }; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
115 static int |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
116 func1 (int a, ...) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
117 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
118 va_list arg; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
119 int i; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
120 va_start (arg, a); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
121 if (a < 4) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
122 i = va_arg (arg, int); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
123 else |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
124 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
125 struct dummy_struct *s = va_arg (arg, struct dummy_struct *); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
126 i = s->value; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
127 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
128 va_end (arg); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
129 return i; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
130 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
131 static int |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
132 func2 (int a, ...) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
133 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
134 va_list arg; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
135 void *p; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
136 va_start (arg, a); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
137 p = va_arg (arg, void *); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
138 va_end (arg); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
139 return func1 (a, p); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
140 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
141 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
142 /* Ensure that all supported fcntl actions are distinct, and |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
143 usable in preprocessor expressions. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
144 static void |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
145 check_flags (void) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
146 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
147 switch (0) |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
148 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
149 case F_DUPFD: |
32147
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
150 #if F_DUPFD |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
151 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
152 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
153 case F_DUPFD_CLOEXEC: |
32147
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
154 #if F_DUPFD_CLOEXEC |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
155 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
156 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
157 case F_GETFD: |
32147
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
158 #if F_GETFD |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
159 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
160 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
161 #ifdef F_SETFD |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
162 case F_SETFD: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
163 # if F_SETFD |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
164 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
165 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
166 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
167 #ifdef F_GETFL |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
168 case F_GETFL: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
169 # if F_GETFL |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
170 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
171 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
172 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
173 #ifdef F_SETFL |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
174 case F_SETFL: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
175 # if F_SETFL |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
176 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
177 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
178 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
179 #ifdef F_GETOWN |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
180 case F_GETOWN: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
181 # if F_GETOWN |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
182 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
183 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
184 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
185 #ifdef F_SETOWN |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
186 case F_SETOWN: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
187 # if F_SETOWN |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
188 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
189 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
190 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
191 #ifdef F_GETLK |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
192 case F_GETLK: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
193 # if F_GETLK |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
194 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
195 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
196 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
197 #ifdef F_SETLK |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
198 case F_SETLK: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
199 # if F_SETLK |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
200 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
201 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
202 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
203 #ifdef F_SETLKW |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
204 case F_SETLKW: |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
205 # if F_SETLKW |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
206 # endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
207 #endif |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
208 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
209 ; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
210 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
211 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
212 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
213 int |
32172 | 214 main (void) |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
215 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
216 const char *file = "test-fcntl.tmp"; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
217 int fd; |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
218 int bad_fd = getdtablesize (); |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
219 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
220 /* Sanity check that rpl_fcntl is likely to work. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
221 ASSERT (func2 (1, 2) == 2); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
222 ASSERT (func2 (2, -2) == -2); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
223 ASSERT (func2 (3, 0x80000000) == 0x80000000); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
224 { |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
225 struct dummy_struct s = { 0L, 4 }; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
226 ASSERT (func2 (4, &s) == 4); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
227 } |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
228 check_flags (); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
229 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
230 /* Assume std descriptors were provided by invoker, and ignore fds |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
231 that might have been inherited. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
232 fd = creat (file, 0600); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
233 ASSERT (STDERR_FILENO < fd); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
234 close (fd + 1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
235 close (fd + 2); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
236 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
237 /* For F_DUPFD*, the source must be valid. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
238 errno = 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
239 ASSERT (fcntl (-1, F_DUPFD, 0) == -1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
240 ASSERT (errno == EBADF); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
241 errno = 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
242 ASSERT (fcntl (fd + 1, F_DUPFD, 0) == -1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
243 ASSERT (errno == EBADF); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
244 errno = 0; |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
245 ASSERT (fcntl (bad_fd, F_DUPFD, 0) == -1); |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
246 ASSERT (errno == EBADF); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
247 errno = 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
248 ASSERT (fcntl (-1, F_DUPFD_CLOEXEC, 0) == -1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
249 ASSERT (errno == EBADF); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
250 errno = 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
251 ASSERT (fcntl (fd + 1, F_DUPFD_CLOEXEC, 0) == -1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
252 ASSERT (errno == EBADF); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
253 errno = 0; |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
254 ASSERT (fcntl (bad_fd, F_DUPFD_CLOEXEC, 0) == -1); |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
255 ASSERT (errno == EBADF); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
256 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
257 /* For F_DUPFD*, the destination must be valid. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
258 errno = 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
259 ASSERT (fcntl (fd, F_DUPFD, -1) == -1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
260 ASSERT (errno == EINVAL); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
261 errno = 0; |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
262 ASSERT (fcntl (fd, F_DUPFD, bad_fd) == -1); |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
263 ASSERT (errno == EINVAL); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
264 errno = 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
265 ASSERT (fcntl (fd, F_DUPFD_CLOEXEC, -1) == -1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
266 ASSERT (errno == EINVAL); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
267 errno = 0; |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
268 ASSERT (fcntl (fd, F_DUPFD_CLOEXEC, bad_fd) == -1); |
39221
f2c01d874a71
Avoid test failures on Microsoft Windows Subsystem for Linux.
Bruno Haible <bruno@clisp.org>
parents:
39199
diff
changeset
|
269 ASSERT (errno == EINVAL |
f2c01d874a71
Avoid test failures on Microsoft Windows Subsystem for Linux.
Bruno Haible <bruno@clisp.org>
parents:
39199
diff
changeset
|
270 || errno == EMFILE /* WSL */); |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
271 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
272 /* For F_DUPFD*, check for correct inheritance, as well as |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
273 preservation of text vs. binary. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
274 setmode (fd, O_BINARY); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
275 ASSERT (is_open (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
276 ASSERT (!is_open (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
277 ASSERT (!is_open (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
278 ASSERT (is_inheritable (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
279 ASSERT (is_mode (fd, O_BINARY)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
280 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
281 ASSERT (fcntl (fd, F_DUPFD, fd) == fd + 1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
282 ASSERT (is_open (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
283 ASSERT (is_open (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
284 ASSERT (!is_open (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
285 ASSERT (is_inheritable (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
286 ASSERT (is_mode (fd, O_BINARY)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
287 ASSERT (is_mode (fd + 1, O_BINARY)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
288 ASSERT (close (fd + 1) == 0); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
289 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
290 ASSERT (fcntl (fd, F_DUPFD_CLOEXEC, fd + 2) == fd + 2); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
291 ASSERT (is_open (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
292 ASSERT (!is_open (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
293 ASSERT (is_open (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
294 ASSERT (is_inheritable (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
295 ASSERT (!is_inheritable (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
296 ASSERT (is_mode (fd, O_BINARY)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
297 ASSERT (is_mode (fd + 2, O_BINARY)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
298 ASSERT (close (fd) == 0); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
299 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
300 setmode (fd + 2, O_TEXT); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
301 ASSERT (fcntl (fd + 2, F_DUPFD, fd + 1) == fd + 1); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
302 ASSERT (!is_open (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
303 ASSERT (is_open (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
304 ASSERT (is_open (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
305 ASSERT (is_inheritable (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
306 ASSERT (!is_inheritable (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
307 ASSERT (is_mode (fd + 1, O_TEXT)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
308 ASSERT (is_mode (fd + 2, O_TEXT)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
309 ASSERT (close (fd + 1) == 0); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
310 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
311 ASSERT (fcntl (fd + 2, F_DUPFD_CLOEXEC, 0) == fd); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
312 ASSERT (is_open (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
313 ASSERT (!is_open (fd + 1)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
314 ASSERT (is_open (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
315 ASSERT (!is_inheritable (fd)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
316 ASSERT (!is_inheritable (fd + 2)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
317 ASSERT (is_mode (fd, O_TEXT)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
318 ASSERT (is_mode (fd + 2, O_TEXT)); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
319 ASSERT (close (fd + 2) == 0); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
320 |
35400 | 321 /* Test F_GETFD on invalid file descriptors. */ |
32147
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
322 errno = 0; |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
323 ASSERT (fcntl (-1, F_GETFD) == -1); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
324 ASSERT (errno == EBADF); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
325 errno = 0; |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
326 ASSERT (fcntl (fd + 1, F_GETFD) == -1); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
327 ASSERT (errno == EBADF); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
328 errno = 0; |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
329 ASSERT (fcntl (bad_fd, F_GETFD) == -1); |
32147
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
330 ASSERT (errno == EBADF); |
35400 | 331 |
332 /* Test F_GETFD, the FD_CLOEXEC bit. */ | |
32147
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
333 { |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
334 int result = fcntl (fd, F_GETFD); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
335 ASSERT (0 <= result); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
336 ASSERT ((result & FD_CLOEXEC) == FD_CLOEXEC); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
337 ASSERT (dup (fd) == fd + 1); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
338 result = fcntl (fd + 1, F_GETFD); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
339 ASSERT (0 <= result); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
340 ASSERT ((result & FD_CLOEXEC) == 0); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
341 ASSERT (close (fd + 1) == 0); |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
342 } |
37d8bfde3c23
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
32145
diff
changeset
|
343 |
35400 | 344 #ifdef F_SETFD |
345 /* Test F_SETFD on invalid file descriptors. */ | |
346 errno = 0; | |
347 ASSERT (fcntl (-1, F_SETFD, 0) == -1); | |
348 ASSERT (errno == EBADF); | |
349 errno = 0; | |
350 ASSERT (fcntl (fd + 1, F_SETFD, 0) == -1); | |
351 ASSERT (errno == EBADF); | |
352 errno = 0; | |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
353 ASSERT (fcntl (bad_fd, F_SETFD, 0) == -1); |
35400 | 354 ASSERT (errno == EBADF); |
355 #endif | |
356 | |
357 #ifdef F_GETFL | |
358 /* Test F_GETFL on invalid file descriptors. */ | |
359 errno = 0; | |
360 ASSERT (fcntl (-1, F_GETFL) == -1); | |
361 ASSERT (errno == EBADF); | |
362 errno = 0; | |
363 ASSERT (fcntl (fd + 1, F_GETFL) == -1); | |
364 ASSERT (errno == EBADF); | |
365 errno = 0; | |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
366 ASSERT (fcntl (bad_fd, F_GETFL) == -1); |
35400 | 367 ASSERT (errno == EBADF); |
368 #endif | |
369 | |
370 #ifdef F_SETFL | |
371 /* Test F_SETFL on invalid file descriptors. */ | |
372 errno = 0; | |
373 ASSERT (fcntl (-1, F_SETFL, 0) == -1); | |
374 ASSERT (errno == EBADF); | |
375 errno = 0; | |
376 ASSERT (fcntl (fd + 1, F_SETFL, 0) == -1); | |
377 ASSERT (errno == EBADF); | |
378 errno = 0; | |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
379 ASSERT (fcntl (bad_fd, F_SETFL, 0) == -1); |
35400 | 380 ASSERT (errno == EBADF); |
381 #endif | |
382 | |
383 #ifdef F_GETOWN | |
384 /* Test F_GETOWN on invalid file descriptors. */ | |
385 errno = 0; | |
386 ASSERT (fcntl (-1, F_GETOWN) == -1); | |
387 ASSERT (errno == EBADF); | |
388 errno = 0; | |
389 ASSERT (fcntl (fd + 1, F_GETOWN) == -1); | |
390 ASSERT (errno == EBADF); | |
391 errno = 0; | |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
392 ASSERT (fcntl (bad_fd, F_GETOWN) == -1); |
35400 | 393 ASSERT (errno == EBADF); |
394 #endif | |
395 | |
396 #ifdef F_SETOWN | |
397 /* Test F_SETFL on invalid file descriptors. */ | |
398 errno = 0; | |
399 ASSERT (fcntl (-1, F_SETOWN, 0) == -1); | |
400 ASSERT (errno == EBADF); | |
401 errno = 0; | |
402 ASSERT (fcntl (fd + 1, F_SETOWN, 0) == -1); | |
403 ASSERT (errno == EBADF); | |
404 errno = 0; | |
37064
2c92a419ee26
tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents:
36940
diff
changeset
|
405 ASSERT (fcntl (bad_fd, F_SETOWN, 0) == -1); |
35400 | 406 ASSERT (errno == EBADF); |
407 #endif | |
408 | |
32145
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
409 /* Cleanup. */ |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
410 ASSERT (close (fd) == 0); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
411 ASSERT (unlink (file) == 0); |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
412 |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
413 return 0; |
c9222c1aec27
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
414 } |