* lisp/play/cookie1.el (cookie-apropos): Minor simplification.
[emacs.git] / lib / sys_select.in.h
blob2af6bfe6f6fbff102af6c235931b26eb309f2674
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)
7 any later version.
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/>. */
17 # if __GNUC__ >= 3
18 @PRAGMA_SYSTEM_HEADER@
19 # endif
20 @PRAGMA_COLUMNS@
22 /* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h>
23 both include <sys/select.h>.
24 On Cygwin, <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 __osf__ && defined _SYS_TYPES_H_ \
28 && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H \
29 && defined _OSF_SOURCE) \
30 || (defined __sun && defined _SYS_TYPES_H \
31 && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
32 || defined __EXTENSIONS__))))
34 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
35 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
37 #elif (@HAVE_SYS_SELECT_H@ \
38 && (defined _CYGWIN_SYS_TIME_H \
39 || (defined __osf__ && defined _SYS_TIME_H_ \
40 && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H \
41 && defined _OSF_SOURCE) \
42 || (defined __sun && defined _SYS_TIME_H \
43 && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
44 || defined __EXTENSIONS__))))
46 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
47 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
49 /* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
50 <sys/bsd_types.h>, which includes <sys/select.h>. At this point we cannot
51 include <signal.h>, because that includes <internal/signal_core.h>, which
52 gives a syntax error because <sys/timespec.h> has not been completely
53 processed. Simply delegate to the system's header in this case. */
54 #elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
56 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
57 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
59 /* On OpenBSD 5.0, <pthread.h> includes <sys/types.h>, which includes
60 <sys/select.h>. At this point we cannot include <signal.h>, because that
61 includes gnulib's pthread.h override, which gives a syntax error because
62 /usr/include/pthread.h has not been completely processed. Simply delegate
63 to the system's header in this case. */
64 #elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && !defined PTHREAD_MUTEX_INITIALIZER)
66 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
68 #else
70 #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
72 /* On many platforms, <sys/select.h> assumes prior inclusion of
73 <sys/types.h>. Also, mingw defines sigset_t there, instead of
74 in <signal.h> where it belongs. */
75 #include <sys/types.h>
77 #if @HAVE_SYS_SELECT_H@
79 /* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
80 of 'struct timeval', and no definition of this type.
81 Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
82 in <sys/time.h>.
83 But avoid namespace pollution on glibc systems. */
84 # ifndef __GLIBC__
85 # include <sys/time.h>
86 # endif
88 /* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
89 that relies on memset(), but without including <string.h>.
90 But in any case avoid namespace pollution on glibc systems. */
91 # if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \
92 && ! defined __GLIBC__
93 # include <string.h>
94 # endif
96 /* The include_next requires a split double-inclusion guard. */
97 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
99 #endif
101 /* Get definition of 'sigset_t'.
102 But avoid namespace pollution on glibc systems.
103 Do this after the include_next (for the sake of OpenBSD 5.0) but before
104 the split double-inclusion guard (for the sake of Solaris). */
105 #if !(defined __GLIBC__ && !defined __UCLIBC__)
106 # include <signal.h>
107 #endif
109 #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
110 #define _@GUARD_PREFIX@_SYS_SELECT_H
112 #if !@HAVE_SYS_SELECT_H@
113 /* A platform that lacks <sys/select.h>. */
114 /* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
115 on most platforms. */
116 # include <sys/time.h>
117 /* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
118 that relies on memset(), but without including <string.h>. */
119 # if defined __hpux
120 # include <string.h>
121 # endif
122 /* On native Windows platforms:
123 Get the 'fd_set' type.
124 Get the close() declaration before we override it. */
125 # if @HAVE_WINSOCK2_H@
126 # if !defined _GL_INCLUDING_WINSOCK2_H
127 # define _GL_INCLUDING_WINSOCK2_H
128 # include <winsock2.h>
129 # undef _GL_INCLUDING_WINSOCK2_H
130 # endif
131 # include <io.h>
132 # endif
133 #endif
135 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
137 /* The definition of _GL_WARN_ON_USE is copied here. */
140 /* Fix some definitions from <winsock2.h>. */
142 #if @HAVE_WINSOCK2_H@
144 # if !GNULIB_defined_rpl_fd_isset
146 /* Re-define FD_ISSET to avoid a WSA call while we are not using
147 network sockets. */
148 static int
149 rpl_fd_isset (SOCKET fd, fd_set * set)
151 u_int i;
152 if (set == NULL)
153 return 0;
155 for (i = 0; i < set->fd_count; i++)
156 if (set->fd_array[i] == fd)
157 return 1;
159 return 0;
162 # define GNULIB_defined_rpl_fd_isset 1
163 # endif
165 # undef FD_ISSET
166 # define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
168 #endif
170 /* Hide some function declarations from <winsock2.h>. */
172 #if @HAVE_WINSOCK2_H@
173 # if !defined _@GUARD_PREFIX@_UNISTD_H
174 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
175 # undef close
176 # define close close_used_without_including_unistd_h
177 # else
178 _GL_WARN_ON_USE (close,
179 "close() used without including <unistd.h>");
180 # endif
181 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
182 # undef gethostname
183 # define gethostname gethostname_used_without_including_unistd_h
184 # else
185 _GL_WARN_ON_USE (gethostname,
186 "gethostname() used without including <unistd.h>");
187 # endif
188 # endif
189 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
190 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191 # undef socket
192 # define socket socket_used_without_including_sys_socket_h
193 # undef connect
194 # define connect connect_used_without_including_sys_socket_h
195 # undef accept
196 # define accept accept_used_without_including_sys_socket_h
197 # undef bind
198 # define bind bind_used_without_including_sys_socket_h
199 # undef getpeername
200 # define getpeername getpeername_used_without_including_sys_socket_h
201 # undef getsockname
202 # define getsockname getsockname_used_without_including_sys_socket_h
203 # undef getsockopt
204 # define getsockopt getsockopt_used_without_including_sys_socket_h
205 # undef listen
206 # define listen listen_used_without_including_sys_socket_h
207 # undef recv
208 # define recv recv_used_without_including_sys_socket_h
209 # undef send
210 # define send send_used_without_including_sys_socket_h
211 # undef recvfrom
212 # define recvfrom recvfrom_used_without_including_sys_socket_h
213 # undef sendto
214 # define sendto sendto_used_without_including_sys_socket_h
215 # undef setsockopt
216 # define setsockopt setsockopt_used_without_including_sys_socket_h
217 # undef shutdown
218 # define shutdown shutdown_used_without_including_sys_socket_h
219 # else
220 _GL_WARN_ON_USE (socket,
221 "socket() used without including <sys/socket.h>");
222 _GL_WARN_ON_USE (connect,
223 "connect() used without including <sys/socket.h>");
224 _GL_WARN_ON_USE (accept,
225 "accept() used without including <sys/socket.h>");
226 _GL_WARN_ON_USE (bind,
227 "bind() used without including <sys/socket.h>");
228 _GL_WARN_ON_USE (getpeername,
229 "getpeername() used without including <sys/socket.h>");
230 _GL_WARN_ON_USE (getsockname,
231 "getsockname() used without including <sys/socket.h>");
232 _GL_WARN_ON_USE (getsockopt,
233 "getsockopt() used without including <sys/socket.h>");
234 _GL_WARN_ON_USE (listen,
235 "listen() used without including <sys/socket.h>");
236 _GL_WARN_ON_USE (recv,
237 "recv() used without including <sys/socket.h>");
238 _GL_WARN_ON_USE (send,
239 "send() used without including <sys/socket.h>");
240 _GL_WARN_ON_USE (recvfrom,
241 "recvfrom() used without including <sys/socket.h>");
242 _GL_WARN_ON_USE (sendto,
243 "sendto() used without including <sys/socket.h>");
244 _GL_WARN_ON_USE (setsockopt,
245 "setsockopt() used without including <sys/socket.h>");
246 _GL_WARN_ON_USE (shutdown,
247 "shutdown() used without including <sys/socket.h>");
248 # endif
249 # endif
250 #endif
253 #if @GNULIB_PSELECT@
254 # if @REPLACE_PSELECT@
255 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
256 # undef pselect
257 # define pselect rpl_pselect
258 # endif
259 _GL_FUNCDECL_RPL (pselect, int,
260 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
261 struct timespec const *restrict, const sigset_t *restrict));
262 _GL_CXXALIAS_RPL (pselect, int,
263 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
264 struct timespec const *restrict, const sigset_t *restrict));
265 # else
266 # if !@HAVE_PSELECT@
267 _GL_FUNCDECL_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_CXXALIAS_SYS (pselect, int,
272 (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
273 struct timespec const *restrict, const sigset_t *restrict));
274 # endif
275 _GL_CXXALIASWARN (pselect);
276 #elif defined GNULIB_POSIXCHECK
277 # undef pselect
278 # if HAVE_RAW_DECL_PSELECT
279 _GL_WARN_ON_USE (pselect, "pselect is not portable - "
280 "use gnulib module pselect for portability");
281 # endif
282 #endif
284 #if @GNULIB_SELECT@
285 # if @REPLACE_SELECT@
286 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
287 # undef select
288 # define select rpl_select
289 # endif
290 _GL_FUNCDECL_RPL (select, int,
291 (int, fd_set *, fd_set *, fd_set *, struct timeval *));
292 _GL_CXXALIAS_RPL (select, int,
293 (int, fd_set *, fd_set *, fd_set *, struct timeval *));
294 # else
295 _GL_CXXALIAS_SYS (select, int,
296 (int, fd_set *, fd_set *, fd_set *, struct timeval *));
297 # endif
298 _GL_CXXALIASWARN (select);
299 #elif @HAVE_WINSOCK2_H@
300 # undef select
301 # define select select_used_without_requesting_gnulib_module_select
302 #elif defined GNULIB_POSIXCHECK
303 # undef select
304 # if HAVE_RAW_DECL_SELECT
305 _GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
306 "use gnulib module select for portability");
307 # endif
308 #endif
311 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
312 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
313 #endif /* OSF/1 */