Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / lib / sys_select.in.h
CommitLineData
3dac6181
AW
1/* Substitute for <sys/select.h>.
2 Copyright (C) 2007-2013 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2, 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 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 <http://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 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)
31
32# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
33# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
34
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)
41
42# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
43# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
44
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)
51
52# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
53# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
54
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)
61
62# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
63
64#else
65
66#ifndef _@GUARD_PREFIX@_SYS_SELECT_H
67
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>
72
73#if @HAVE_SYS_SELECT_H@
74
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()
78 in <sys/time.h>.
79 But avoid namespace pollution on glibc systems. */
80# ifndef __GLIBC__
81# include <sys/time.h>
82# endif
83
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__
89# include <string.h>
90# endif
91
92/* The include_next requires a split double-inclusion guard. */
93# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
94
95#endif
96
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__)
102# include <signal.h>
103#endif
104
105#ifndef _@GUARD_PREFIX@_SYS_SELECT_H
106#define _@GUARD_PREFIX@_SYS_SELECT_H
107
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>. */
115# if defined __hpux
116# include <string.h>
117# endif
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
126# endif
127# include <io.h>
128# endif
129#endif
130
131/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
132
133/* The definition of _GL_WARN_ON_USE is copied here. */
134
135
136/* Fix some definitions from <winsock2.h>. */
137
138#if @HAVE_WINSOCK2_H@
139
140# if !GNULIB_defined_rpl_fd_isset
141
142/* Re-define FD_ISSET to avoid a WSA call while we are not using
143 network sockets. */
144static int
145rpl_fd_isset (SOCKET fd, fd_set * set)
146{
147 u_int i;
148 if (set == NULL)
149 return 0;
150
151 for (i = 0; i < set->fd_count; i++)
152 if (set->fd_array[i] == fd)
153 return 1;
154
155 return 0;
156}
157
158# define GNULIB_defined_rpl_fd_isset 1
159# endif
160
161# undef FD_ISSET
162# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
163
164#endif
165
166/* Hide some function declarations from <winsock2.h>. */
167
168#if @HAVE_WINSOCK2_H@
169# if !defined _@GUARD_PREFIX@_UNISTD_H
170# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
171# undef close
172# define close close_used_without_including_unistd_h
173# else
174 _GL_WARN_ON_USE (close,
175 "close() used without including <unistd.h>");
176# endif
177# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
178# undef gethostname
179# define gethostname gethostname_used_without_including_unistd_h
180# else
181 _GL_WARN_ON_USE (gethostname,
182 "gethostname() used without including <unistd.h>");
183# endif
184# endif
185# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
186# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
187# undef socket
188# define socket socket_used_without_including_sys_socket_h
189# undef connect
190# define connect connect_used_without_including_sys_socket_h
191# undef accept
192# define accept accept_used_without_including_sys_socket_h
193# undef bind
194# define bind bind_used_without_including_sys_socket_h
195# undef getpeername
196# define getpeername getpeername_used_without_including_sys_socket_h
197# undef getsockname
198# define getsockname getsockname_used_without_including_sys_socket_h
199# undef getsockopt
200# define getsockopt getsockopt_used_without_including_sys_socket_h
201# undef listen
202# define listen listen_used_without_including_sys_socket_h
203# undef recv
204# define recv recv_used_without_including_sys_socket_h
205# undef send
206# define send send_used_without_including_sys_socket_h
207# undef recvfrom
208# define recvfrom recvfrom_used_without_including_sys_socket_h
209# undef sendto
210# define sendto sendto_used_without_including_sys_socket_h
211# undef setsockopt
212# define setsockopt setsockopt_used_without_including_sys_socket_h
213# undef shutdown
214# define shutdown shutdown_used_without_including_sys_socket_h
215# else
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>");
244# endif
245# endif
246#endif
247
248
249#if @GNULIB_PSELECT@
250# if @REPLACE_PSELECT@
251# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
252# undef pselect
253# define pselect rpl_pselect
254# endif
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));
261# else
262# if !@HAVE_PSELECT@
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));
266# endif
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));
270# endif
271_GL_CXXALIASWARN (pselect);
272#elif defined GNULIB_POSIXCHECK
273# undef pselect
274# if HAVE_RAW_DECL_PSELECT
275_GL_WARN_ON_USE (pselect, "pselect is not portable - "
276 "use gnulib module pselect for portability");
277# endif
278#endif
279
280#if @GNULIB_SELECT@
281# if @REPLACE_SELECT@
282# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
283# undef select
284# define select rpl_select
285# endif
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 *));
290# else
291_GL_CXXALIAS_SYS (select, int,
292 (int, fd_set *, fd_set *, fd_set *, struct timeval *));
293# endif
294_GL_CXXALIASWARN (select);
295#elif @HAVE_WINSOCK2_H@
296# undef select
297# define select select_used_without_requesting_gnulib_module_select
298#elif defined GNULIB_POSIXCHECK
299# undef select
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");
303# endif
304#endif
305
306
307#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
308#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
309#endif /* OSF/1 */