source: trunk/src/sed/gnulib-tests/sys_select.in.h

Last change on this file was 3611, checked in by bird, 10 months ago

vendor/sed/current: GNU sed 4.9 (sed-4.9.tar.xz sha256:6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181)

File size: 12.8 KB
Line 
1/* Substitute for <sys/select.h>.
2 Copyright (C) 2007-2022 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17# if __GNUC__ >= 3
18@PRAGMA_SYSTEM_HEADER@
19# endif
20@PRAGMA_COLUMNS@
21
22/* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h>
23 both include <sys/select.h>.
24 On Cygwin and OpenBSD, <sys/time.h> includes <sys/select.h>.
25 Simply delegate to the system's header in this case. */
26#if (@HAVE_SYS_SELECT_H@ \
27 && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H \
28 && ((defined __osf__ && defined _SYS_TYPES_H_ \
29 && defined _OSF_SOURCE) \
30 || (defined __sun && defined _SYS_TYPES_H \
31 && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
32 || defined __EXTENSIONS__))))
33
34# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
35# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
36
37#elif (@HAVE_SYS_SELECT_H@ \
38 && (defined _CYGWIN_SYS_TIME_H \
39 || (!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H \
40 && ((defined __osf__ && defined _SYS_TIME_H_ \
41 && defined _OSF_SOURCE) \
42 || (defined __OpenBSD__ && defined _SYS_TIME_H_) \
43 || (defined __sun && defined _SYS_TIME_H \
44 && (! (defined _XOPEN_SOURCE \
45 || defined _POSIX_C_SOURCE) \
46 || defined __EXTENSIONS__))))))
47
48# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
49# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
50
51/* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
52 <sys/bsd_types.h>, which includes <sys/select.h>. At this point we cannot
53 include <signal.h>, because that includes <internal/signal_core.h>, which
54 gives a syntax error because <sys/timespec.h> has not been completely
55 processed. Simply delegate to the system's header in this case. */
56#elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
57
58# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
59# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
60
61/* On OpenBSD 5.0, <pthread.h> includes <sys/types.h>, which includes
62 <sys/select.h>. At this point we cannot include <signal.h>, because that
63 includes gnulib's pthread.h override, which gives a syntax error because
64 /usr/include/pthread.h has not been completely processed. Simply delegate
65 to the system's header in this case. */
66#elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && !defined PTHREAD_MUTEX_INITIALIZER)
67
68# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
69
70#else
71
72#ifndef _@GUARD_PREFIX@_SYS_SELECT_H
73
74/* On many platforms, <sys/select.h> assumes prior inclusion of
75 <sys/types.h>. Also, mingw defines sigset_t there, instead of
76 in <signal.h> where it belongs. */
77#include <sys/types.h>
78
79#if @HAVE_SYS_SELECT_H@
80
81/* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
82 of 'struct timeval', and no definition of this type.
83 Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
84 in <sys/time.h>.
85 But avoid namespace pollution on glibc systems, a circular include
86 <sys/select.h> -> <sys/time.h> -> <sys/select.h> on FreeBSD 13.1, and
87 "unknown type name" problems on Cygwin. */
88# if !(defined __GLIBC__ || defined __FreeBSD__ || defined __CYGWIN__)
89# include <sys/time.h>
90# endif
91
92/* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
93 that relies on memset(), but without including <string.h>.
94 But in any case avoid namespace pollution on glibc systems. */
95# if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \
96 && ! defined __GLIBC__
97# include <string.h>
98# endif
99
100/* The include_next requires a split double-inclusion guard. */
101# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
102
103#endif
104
105/* Get definition of 'sigset_t'.
106 But avoid namespace pollution on glibc systems and "unknown type
107 name" problems on Cygwin.
108 On OS/2 kLIBC, sigset_t is defined in <sys/select.h>, too. In addition,
109 if <sys/param.h> is included, <types.h> -> <sys/types.h> -> <sys/select.h>
110 are included. Then <signal.h> -> <pthread.h> are included by GNULIB. By the
111 way, <pthread.h> requires PAGE_SIZE defined in <sys/param.h>. However,
112 <sys/param.h> has not been processed, yet. As a result, 'PAGE_SIZE'
113 undeclared error occurs in <pthread.h>.
114 Do this after the include_next (for the sake of OpenBSD 5.0) but before
115 the split double-inclusion guard (for the sake of Solaris). */
116#if !((defined __GLIBC__ || defined __CYGWIN__ || defined __KLIBC__) \
117 && !defined __UCLIBC__)
118# include <signal.h>
119#endif
120
121#ifndef _@GUARD_PREFIX@_SYS_SELECT_H
122#define _@GUARD_PREFIX@_SYS_SELECT_H
123
124#if !@HAVE_SYS_SELECT_H@
125/* A platform that lacks <sys/select.h>. */
126/* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
127 on most platforms. */
128# include <sys/time.h>
129/* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
130 that relies on memset(), but without including <string.h>. */
131# if defined __hpux
132# include <string.h>
133# endif
134/* On native Windows platforms:
135 Get the 'fd_set' type.
136 Get the close() declaration before we override it. */
137# if @HAVE_WINSOCK2_H@
138# if !defined _GL_INCLUDING_WINSOCK2_H
139# define _GL_INCLUDING_WINSOCK2_H
140# include <winsock2.h>
141# undef _GL_INCLUDING_WINSOCK2_H
142# endif
143# include <io.h>
144# endif
145#endif
146
147/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
148
149/* The definition of _GL_WARN_ON_USE is copied here. */
150
151
152/* Fix some definitions from <winsock2.h>. */
153
154#if @HAVE_WINSOCK2_H@
155
156# if !GNULIB_defined_rpl_fd_isset
157
158/* Re-define FD_ISSET to avoid a WSA call while we are not using
159 network sockets. */
160static int
161rpl_fd_isset (SOCKET fd, fd_set * set)
162{
163 u_int i;
164 if (set == NULL)
165 return 0;
166
167 for (i = 0; i < set->fd_count; i++)
168 if (set->fd_array[i] == fd)
169 return 1;
170
171 return 0;
172}
173
174# define GNULIB_defined_rpl_fd_isset 1
175# endif
176
177# undef FD_ISSET
178# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
179
180#endif
181
182/* Hide some function declarations from <winsock2.h>. */
183
184#if @HAVE_WINSOCK2_H@
185# if !defined _@GUARD_PREFIX@_UNISTD_H
186# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
187# undef close
188# define close close_used_without_including_unistd_h
189# elif !defined __clang__
190 _GL_WARN_ON_USE (close,
191 "close() used without including <unistd.h>");
192# endif
193# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
194# undef gethostname
195# define gethostname gethostname_used_without_including_unistd_h
196# elif !defined __clang__
197 _GL_WARN_ON_USE (gethostname,
198 "gethostname() used without including <unistd.h>");
199# endif
200# endif
201# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
202# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
203# undef socket
204# define socket socket_used_without_including_sys_socket_h
205# undef connect
206# define connect connect_used_without_including_sys_socket_h
207# undef accept
208# define accept accept_used_without_including_sys_socket_h
209# undef bind
210# define bind bind_used_without_including_sys_socket_h
211# undef getpeername
212# define getpeername getpeername_used_without_including_sys_socket_h
213# undef getsockname
214# define getsockname getsockname_used_without_including_sys_socket_h
215# undef getsockopt
216# define getsockopt getsockopt_used_without_including_sys_socket_h
217# undef listen
218# define listen listen_used_without_including_sys_socket_h
219# undef recv
220# define recv recv_used_without_including_sys_socket_h
221# undef send
222# define send send_used_without_including_sys_socket_h
223# undef recvfrom
224# define recvfrom recvfrom_used_without_including_sys_socket_h
225# undef sendto
226# define sendto sendto_used_without_including_sys_socket_h
227# undef setsockopt
228# define setsockopt setsockopt_used_without_including_sys_socket_h
229# undef shutdown
230# define shutdown shutdown_used_without_including_sys_socket_h
231# elif !defined __clang__
232 _GL_WARN_ON_USE (socket,
233 "socket() used without including <sys/socket.h>");
234 _GL_WARN_ON_USE (connect,
235 "connect() used without including <sys/socket.h>");
236 _GL_WARN_ON_USE (accept,
237 "accept() used without including <sys/socket.h>");
238 _GL_WARN_ON_USE (bind,
239 "bind() used without including <sys/socket.h>");
240 _GL_WARN_ON_USE (getpeername,
241 "getpeername() used without including <sys/socket.h>");
242 _GL_WARN_ON_USE (getsockname,
243 "getsockname() used without including <sys/socket.h>");
244 _GL_WARN_ON_USE (getsockopt,
245 "getsockopt() used without including <sys/socket.h>");
246 _GL_WARN_ON_USE (listen,
247 "listen() used without including <sys/socket.h>");
248 _GL_WARN_ON_USE (recv,
249 "recv() used without including <sys/socket.h>");
250 _GL_WARN_ON_USE (send,
251 "send() used without including <sys/socket.h>");
252 _GL_WARN_ON_USE (recvfrom,
253 "recvfrom() used without including <sys/socket.h>");
254 _GL_WARN_ON_USE (sendto,
255 "sendto() used without including <sys/socket.h>");
256 _GL_WARN_ON_USE (setsockopt,
257 "setsockopt() used without including <sys/socket.h>");
258 _GL_WARN_ON_USE (shutdown,
259 "shutdown() used without including <sys/socket.h>");
260# endif
261# endif
262#endif
263
264
265#if @GNULIB_PSELECT@
266# if @REPLACE_PSELECT@
267# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
268# undef pselect
269# define pselect rpl_pselect
270# endif
271_GL_FUNCDECL_RPL (pselect, int,
272 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
273 struct timespec const *restrict, const sigset_t *restrict));
274_GL_CXXALIAS_RPL (pselect, int,
275 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
276 struct timespec const *restrict, const sigset_t *restrict));
277# else
278# if !@HAVE_PSELECT@
279_GL_FUNCDECL_SYS (pselect, int,
280 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
281 struct timespec const *restrict, const sigset_t *restrict));
282# endif
283/* Need to cast, because on AIX 7, the second, third, fourth argument may be
284 void *restrict, void *restrict, void *restrict. */
285_GL_CXXALIAS_SYS_CAST (pselect, int,
286 (int,
287 fd_set *restrict, fd_set *restrict, fd_set *restrict,
288 struct timespec const *restrict,
289 const sigset_t *restrict));
290# endif
291# if __GLIBC__ >= 2
292_GL_CXXALIASWARN (pselect);
293# endif
294#elif defined GNULIB_POSIXCHECK
295# undef pselect
296# if HAVE_RAW_DECL_PSELECT
297_GL_WARN_ON_USE (pselect, "pselect is not portable - "
298 "use gnulib module pselect for portability");
299# endif
300#endif
301
302#if @GNULIB_SELECT@
303# if @REPLACE_SELECT@
304# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
305# undef select
306# define select rpl_select
307# endif
308_GL_FUNCDECL_RPL (select, int,
309 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
310 struct timeval *restrict));
311_GL_CXXALIAS_RPL (select, int,
312 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
313 timeval *restrict));
314# else
315_GL_CXXALIAS_SYS (select, int,
316 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
317 timeval *restrict));
318# endif
319_GL_CXXALIASWARN (select);
320#elif @HAVE_WINSOCK2_H@
321# undef select
322# define select select_used_without_requesting_gnulib_module_select
323#elif defined GNULIB_POSIXCHECK
324# undef select
325# if HAVE_RAW_DECL_SELECT
326_GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
327 "use gnulib module select for portability");
328# endif
329#endif
330
331
332#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
333#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
334#endif /* OSF/1 */
Note: See TracBrowser for help on using the repository browser.