Debian Codegraph @

lib/sys_select.in.h

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