1 /* Substitute for <sys/select.h>.
2 Copyright (C) 2007-2013 Free Software Foundation, Inc.
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)
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */
18 @PRAGMA_SYSTEM_HEADER@
22 /* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h>
23 both include <sys/select.h>.
24 Simply delegate to the system's header in this case. */
25 #if (@HAVE_SYS_SELECT_H@ \
26 && ((defined __osf__ && defined _SYS_TYPES_H_ && defined _OSF_SOURCE) \
27 || (defined __sun && defined _SYS_TYPES_H \
28 && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
29 || defined __EXTENSIONS__))) \
30 && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H)
32 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
33 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
35 #elif (@HAVE_SYS_SELECT_H@ \
36 && ((defined __osf__ && defined _SYS_TIME_H_ && defined _OSF_SOURCE) \
37 || (defined __sun && defined _SYS_TIME_H \
38 && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
39 || defined __EXTENSIONS__))) \
40 && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H)
42 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
43 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
45 /* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
46 <sys/bsd_types.h>, which includes <sys/select.h>. At this point we cannot
47 include <signal.h>, because that includes <internal/signal_core.h>, which
48 gives a syntax error because <sys/timespec.h> has not been completely
49 processed. Simply delegate to the system's header in this case. */
50 #elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
52 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
53 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
55 /* On OpenBSD 5.0, <pthread.h> includes <sys/types.h>, which includes
56 <sys/select.h>. At this point we cannot include <signal.h>, because that
57 includes gnulib's pthread.h override, which gives a syntax error because
58 /usr/include/pthread.h has not been completely processed. Simply delegate
59 to the system's header in this case. */
60 #elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && !defined PTHREAD_MUTEX_INITIALIZER)
62 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
66 #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
68 /* On many platforms, <sys/select.h> assumes prior inclusion of
69 <sys/types.h>. Also, mingw defines sigset_t there, instead of
70 in <signal.h> where it belongs. */
71 #include <sys/types.h>
73 #if @HAVE_SYS_SELECT_H@
75 /* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
76 of 'struct timeval', and no definition of this type.
77 Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
79 But avoid namespace pollution on glibc systems. */
81 # include <sys/time.h>
84 /* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
85 that relies on memset(), but without including <string.h>.
86 But in any case avoid namespace pollution on glibc systems. */
87 # if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \
88 && ! defined __GLIBC__
92 /* The include_next requires a split double-inclusion guard. */
93 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
97 /* Get definition of 'sigset_t'.
98 But avoid namespace pollution on glibc systems.
99 Do this after the include_next (for the sake of OpenBSD 5.0) but before
100 the split double-inclusion guard (for the sake of Solaris). */
101 #if !(defined __GLIBC__ && !defined __UCLIBC__)
105 #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
106 #define _@GUARD_PREFIX@_SYS_SELECT_H
108 #if !@HAVE_SYS_SELECT_H@
109 /* A platform that lacks <sys/select.h>. */
110 /* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
111 on most platforms. */
112 # include <sys/time.h>
113 /* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
114 that relies on memset(), but without including <string.h>. */
118 /* On native Windows platforms:
119 Get the 'fd_set' type.
120 Get the close() declaration before we override it. */
121 # if @HAVE_WINSOCK2_H@
122 # if !defined _GL_INCLUDING_WINSOCK2_H
123 # define _GL_INCLUDING_WINSOCK2_H
124 # include <winsock2.h>
125 # undef _GL_INCLUDING_WINSOCK2_H
131 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
133 /* The definition of _GL_WARN_ON_USE is copied here. */
136 /* Fix some definitions from <winsock2.h>. */
138 #if @HAVE_WINSOCK2_H@
140 # if !GNULIB_defined_rpl_fd_isset
142 /* Re-define FD_ISSET to avoid a WSA call while we are not using
145 rpl_fd_isset (SOCKET fd
, fd_set
* set
)
151 for (i
= 0; i
< set
->fd_count
; i
++)
152 if (set
->fd_array
[i
] == fd
)
158 # define GNULIB_defined_rpl_fd_isset 1
162 # define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
166 /* Hide some function declarations from <winsock2.h>. */
168 #if @HAVE_WINSOCK2_H@
169 # if !defined _@GUARD_PREFIX@_UNISTD_H
170 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
172 # define close close_used_without_including_unistd_h
174 _GL_WARN_ON_USE (close
,
175 "close() used without including <unistd.h>");
177 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
179 # define gethostname gethostname_used_without_including_unistd_h
181 _GL_WARN_ON_USE (gethostname
,
182 "gethostname() used without including <unistd.h>");
185 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
186 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
188 # define socket socket_used_without_including_sys_socket_h
190 # define connect connect_used_without_including_sys_socket_h
192 # define accept accept_used_without_including_sys_socket_h
194 # define bind bind_used_without_including_sys_socket_h
196 # define getpeername getpeername_used_without_including_sys_socket_h
198 # define getsockname getsockname_used_without_including_sys_socket_h
200 # define getsockopt getsockopt_used_without_including_sys_socket_h
202 # define listen listen_used_without_including_sys_socket_h
204 # define recv recv_used_without_including_sys_socket_h
206 # define send send_used_without_including_sys_socket_h
208 # define recvfrom recvfrom_used_without_including_sys_socket_h
210 # define sendto sendto_used_without_including_sys_socket_h
212 # define setsockopt setsockopt_used_without_including_sys_socket_h
214 # define shutdown shutdown_used_without_including_sys_socket_h
216 _GL_WARN_ON_USE (socket
,
217 "socket() used without including <sys/socket.h>");
218 _GL_WARN_ON_USE (connect
,
219 "connect() used without including <sys/socket.h>");
220 _GL_WARN_ON_USE (accept
,
221 "accept() used without including <sys/socket.h>");
222 _GL_WARN_ON_USE (bind
,
223 "bind() used without including <sys/socket.h>");
224 _GL_WARN_ON_USE (getpeername
,
225 "getpeername() used without including <sys/socket.h>");
226 _GL_WARN_ON_USE (getsockname
,
227 "getsockname() used without including <sys/socket.h>");
228 _GL_WARN_ON_USE (getsockopt
,
229 "getsockopt() used without including <sys/socket.h>");
230 _GL_WARN_ON_USE (listen
,
231 "listen() used without including <sys/socket.h>");
232 _GL_WARN_ON_USE (recv
,
233 "recv() used without including <sys/socket.h>");
234 _GL_WARN_ON_USE (send
,
235 "send() used without including <sys/socket.h>");
236 _GL_WARN_ON_USE (recvfrom
,
237 "recvfrom() used without including <sys/socket.h>");
238 _GL_WARN_ON_USE (sendto
,
239 "sendto() used without including <sys/socket.h>");
240 _GL_WARN_ON_USE (setsockopt
,
241 "setsockopt() used without including <sys/socket.h>");
242 _GL_WARN_ON_USE (shutdown
,
243 "shutdown() used without including <sys/socket.h>");
250 # if @REPLACE_PSELECT@
251 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
253 # define pselect rpl_pselect
255 _GL_FUNCDECL_RPL (pselect
, int,
256 (int, fd_set
*restrict
, fd_set
*restrict
, fd_set
*restrict
,
257 struct timespec
const *restrict
, const sigset_t
*restrict
));
258 _GL_CXXALIAS_RPL (pselect
, int,
259 (int, fd_set
*restrict
, fd_set
*restrict
, fd_set
*restrict
,
260 struct timespec
const *restrict
, const sigset_t
*restrict
));
263 _GL_FUNCDECL_SYS (pselect
, int,
264 (int, fd_set
*restrict
, fd_set
*restrict
, fd_set
*restrict
,
265 struct timespec
const *restrict
, const sigset_t
*restrict
));
267 _GL_CXXALIAS_SYS (pselect
, int,
268 (int, fd_set
*restrict
, fd_set
*restrict
, fd_set
*restrict
,
269 struct timespec
const *restrict
, const sigset_t
*restrict
));
271 _GL_CXXALIASWARN (pselect
);
272 #elif defined GNULIB_POSIXCHECK
274 # if HAVE_RAW_DECL_PSELECT
275 _GL_WARN_ON_USE (pselect
, "pselect is not portable - "
276 "use gnulib module pselect for portability");
281 # if @REPLACE_SELECT@
282 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
284 # define select rpl_select
286 _GL_FUNCDECL_RPL (select
, int,
287 (int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*));
288 _GL_CXXALIAS_RPL (select
, int,
289 (int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*));
291 _GL_CXXALIAS_SYS (select
, int,
292 (int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*));
294 _GL_CXXALIASWARN (select
);
295 #elif @HAVE_WINSOCK2_H@
297 # define select select_used_without_requesting_gnulib_module_select
298 #elif defined GNULIB_POSIXCHECK
300 # if HAVE_RAW_DECL_SELECT
301 _GL_WARN_ON_USE (select
, "select is not always POSIX compliant - "
302 "use gnulib module select for portability");
307 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
308 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */