Mercurial > gnulib
annotate tests/test-pipe2.c @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
11871 | 1 /* Test of pipe2. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19595
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
11871 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
11871 | 16 |
17 #include <config.h> | |
18 | |
19 #include <unistd.h> | |
20 | |
12489 | 21 #include "signature.h" |
22 SIGNATURE_CHECK (pipe2, int, (int[2], int)); | |
23 | |
11871 | 24 #include <fcntl.h> |
25 #include <stdbool.h> | |
26 | |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
27 #if defined _WIN32 && ! defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
28 /* Get declarations of the native Windows API functions. */ |
11871 | 29 # define WIN32_LEAN_AND_MEAN |
30 # include <windows.h> | |
15752
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14856
diff
changeset
|
31 /* Get _get_osfhandle. */ |
18883
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
32 # if GNULIB_MSVC_NOTHROW |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
33 # include "msvc-nothrow.h" |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
34 # else |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
35 # include <io.h> |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
36 # endif |
11871 | 37 #endif |
38 | |
39 #include "binary-io.h" | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
40 #include "macros.h" |
14856
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
41 #if GNULIB_NONBLOCKING |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
42 # include "nonblocking.h" |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
43 #endif |
11871 | 44 |
45 /* Return true if FD is open. */ | |
46 static bool | |
47 is_open (int fd) | |
48 { | |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
49 #if defined _WIN32 && ! defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
50 /* On native Windows, the initial state of unassigned standard file |
11871 | 51 descriptors is that they are open but point to an |
52 INVALID_HANDLE_VALUE, and there is no fcntl. */ | |
53 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; | |
54 #else | |
55 # ifndef F_GETFL | |
56 # error Please port fcntl to your platform | |
57 # endif | |
58 return 0 <= fcntl (fd, F_GETFL); | |
59 #endif | |
60 } | |
61 | |
62 /* Return true if FD is not inherited to child processes. */ | |
63 static bool | |
64 is_cloexec (int fd) | |
65 { | |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
66 #if defined _WIN32 && ! defined __CYGWIN__ |
11871 | 67 HANDLE h = (HANDLE) _get_osfhandle (fd); |
68 DWORD flags; | |
69 ASSERT (GetHandleInformation (h, &flags)); | |
70 return (flags & HANDLE_FLAG_INHERIT) == 0; | |
71 #else | |
72 int flags; | |
73 ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0); | |
74 return (flags & FD_CLOEXEC) != 0; | |
75 #endif | |
76 } | |
77 | |
14856
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
78 #if ! GNULIB_NONBLOCKING |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
79 static int |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
80 get_nonblocking_flag (int fd) |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
81 { |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
82 # if defined _WIN32 && ! defined __CYGWIN__ |
14856
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
83 return 0; |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
84 # else |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
85 # ifndef F_GETFL |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
86 # error Please port fcntl to your platform |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
87 # endif |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
88 int flags; |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
89 ASSERT ((flags = fcntl (fd, F_GETFL)) >= 0); |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
90 return (flags & O_NONBLOCK) != 0; |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
91 # endif |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
92 } |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
93 #endif |
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
94 |
11871 | 95 int |
96 main () | |
97 { | |
98 int use_nonblocking; | |
99 int use_cloexec; | |
100 | |
14856
c593fd7d2ab9
pipe2: Remove dependency on 'nonblocking' module.
Bruno Haible <bruno@clisp.org>
parents:
14535
diff
changeset
|
101 for (use_nonblocking = 0; use_nonblocking <= !!O_NONBLOCK; use_nonblocking++) |
14535
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
102 for (use_cloexec = 0; use_cloexec <= !!O_CLOEXEC; use_cloexec++) |
11871 | 103 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
104 int o_flags; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
105 int fd[2]; |
11871 | 106 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
107 o_flags = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
108 if (use_nonblocking) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
109 o_flags |= O_NONBLOCK; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
110 if (use_cloexec) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
111 o_flags |= O_CLOEXEC; |
11871 | 112 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
113 fd[0] = -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
114 fd[1] = -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
115 ASSERT (pipe2 (fd, o_flags) >= 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
116 ASSERT (fd[0] >= 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
117 ASSERT (fd[1] >= 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
118 ASSERT (fd[0] != fd[1]); |
13832
992d47604da1
tests: fix compiler warnings
Eric Blake <eblake@redhat.com>
parents:
13664
diff
changeset
|
119 ASSERT (is_open (fd[0])); |
992d47604da1
tests: fix compiler warnings
Eric Blake <eblake@redhat.com>
parents:
13664
diff
changeset
|
120 ASSERT (is_open (fd[1])); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
121 if (use_cloexec) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
122 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
123 ASSERT (is_cloexec (fd[0])); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
124 ASSERT (is_cloexec (fd[1])); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
125 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
126 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
127 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
128 ASSERT (!is_cloexec (fd[0])); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
129 ASSERT (!is_cloexec (fd[1])); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
130 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
131 if (use_nonblocking) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
132 { |
14535
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
133 ASSERT (get_nonblocking_flag (fd[0]) == 1); |
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
134 ASSERT (get_nonblocking_flag (fd[1]) == 1); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
135 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
136 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
137 { |
14535
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
138 ASSERT (get_nonblocking_flag (fd[0]) == 0); |
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
139 ASSERT (get_nonblocking_flag (fd[1]) == 0); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11871
diff
changeset
|
140 } |
14535
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
141 |
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
142 ASSERT (close (fd[0]) == 0); |
7ba508565384
pipe2: fix O_NONBLOCK support on mingw
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
143 ASSERT (close (fd[1]) == 0); |
11871 | 144 } |
145 | |
146 return 0; | |
147 } |