sys_select: Avoid a syntax error regarding timespec_t on IRIX 6.5.
[gnulib.git] / lib / sys_select.in.h
1 /* Substitute for <sys/select.h>.
2    Copyright (C) 2007-2011 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 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 General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 # if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 # endif
21 @PRAGMA_COLUMNS@
22
23 /* On OSF/1, <sys/types.h> and <sys/time.h> include <sys/select.h>.
24    Simply delegate to the system's header in this case.  */
25 #if @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TYPES_H_ && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H) && defined _OSF_SOURCE
26
27 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
28 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
29
30 #elif @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TIME_H_ && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H) && defined _OSF_SOURCE
31
32 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
33 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
34
35 /* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
36    <sys/bsd_types.h>, which includes <sys/select.h>.  At this point we cannot
37    include <signal.h>, because that includes <internal/signal_core.h>, which
38    gives a syntax error because <sys/timespec.h> has not been completely
39    processed.  Simply delegate to the system's header in this case.  */
40 #elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
41
42 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
43 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
44
45 #else
46
47 #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
48
49 /* On many platforms, <sys/select.h> assumes prior inclusion of
50    <sys/types.h>.  Also, mingw defines sigset_t there, instead of
51    in <signal.h> where it belongs.  */
52 #include <sys/types.h>
53
54 /* Get definition of 'sigset_t'.
55    But avoid namespace pollution on glibc systems.  */
56 #if !(defined __GLIBC__ && !defined __UCLIBC__)
57 # include <signal.h>
58 #endif
59
60 #if @HAVE_SYS_SELECT_H@
61
62 /* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
63    of 'struct timeval', and no definition of this type.
64    Also, MacOS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
65    in <sys/time.h>.
66    But avoid namespace pollution on glibc systems.  */
67 # ifndef __GLIBC__
68 #  include <sys/time.h>
69 # endif
70
71 /* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
72    that relies on memset(), but without including <string.h>.
73    But in any case avoid namespace pollution on glibc systems.  */
74 # if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \
75      && ! defined __GLIBC__
76 #  include <string.h>
77 # endif
78
79 /* The include_next requires a split double-inclusion guard.  */
80 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
81
82 #endif
83
84 #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
85 #define _@GUARD_PREFIX@_SYS_SELECT_H
86
87 #if !@HAVE_SYS_SELECT_H@
88 /* A platform that lacks <sys/select.h>.  */
89 /* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
90    on most platforms.  */
91 # include <sys/time.h>
92 /* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
93    that relies on memset(), but without including <string.h>.  */
94 # if defined __hpux
95 #  include <string.h>
96 # endif
97 /* On native Windows platforms:
98    Get the 'fd_set' type.  */
99 # if @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
100 #  define _GL_INCLUDING_WINSOCK2_H
101 #  include <winsock2.h>
102 #  undef _GL_INCLUDING_WINSOCK2_H
103 # endif
104 #endif
105
106 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
107
108 /* The definition of _GL_WARN_ON_USE is copied here.  */
109
110
111 /* Fix some definitions from <winsock2.h>.  */
112
113 #if @HAVE_WINSOCK2_H@
114
115 # if !GNULIB_defined_rpl_fd_isset
116
117 /* Re-define FD_ISSET to avoid a WSA call while we are not using
118    network sockets.  */
119 static inline int
120 rpl_fd_isset (SOCKET fd, fd_set * set)
121 {
122   u_int i;
123   if (set == NULL)
124     return 0;
125
126   for (i = 0; i < set->fd_count; i++)
127     if (set->fd_array[i] == fd)
128       return 1;
129
130   return 0;
131 }
132
133 #  define GNULIB_defined_rpl_fd_isset 1
134 # endif
135
136 # undef FD_ISSET
137 # define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
138
139 #endif
140
141 /* Hide some function declarations from <winsock2.h>.  */
142
143 #if @HAVE_WINSOCK2_H@
144 # if !defined _@GUARD_PREFIX@_UNISTD_H
145 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
146 #   undef close
147 #   define close close_used_without_including_unistd_h
148 #  else
149     _GL_WARN_ON_USE (close,
150                      "close() used without including <unistd.h>");
151 #  endif
152 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
153 #   undef gethostname
154 #   define gethostname gethostname_used_without_including_unistd_h
155 #  else
156     _GL_WARN_ON_USE (gethostname,
157                      "gethostname() used without including <unistd.h>");
158 #  endif
159 # endif
160 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
161 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
162 #   undef socket
163 #   define socket              socket_used_without_including_sys_socket_h
164 #   undef connect
165 #   define connect             connect_used_without_including_sys_socket_h
166 #   undef accept
167 #   define accept              accept_used_without_including_sys_socket_h
168 #   undef bind
169 #   define bind                bind_used_without_including_sys_socket_h
170 #   undef getpeername
171 #   define getpeername         getpeername_used_without_including_sys_socket_h
172 #   undef getsockname
173 #   define getsockname         getsockname_used_without_including_sys_socket_h
174 #   undef getsockopt
175 #   define getsockopt          getsockopt_used_without_including_sys_socket_h
176 #   undef listen
177 #   define listen              listen_used_without_including_sys_socket_h
178 #   undef recv
179 #   define recv                recv_used_without_including_sys_socket_h
180 #   undef send
181 #   define send                send_used_without_including_sys_socket_h
182 #   undef recvfrom
183 #   define recvfrom            recvfrom_used_without_including_sys_socket_h
184 #   undef sendto
185 #   define sendto              sendto_used_without_including_sys_socket_h
186 #   undef setsockopt
187 #   define setsockopt          setsockopt_used_without_including_sys_socket_h
188 #   undef shutdown
189 #   define shutdown            shutdown_used_without_including_sys_socket_h
190 #  else
191     _GL_WARN_ON_USE (socket,
192                      "socket() used without including <sys/socket.h>");
193     _GL_WARN_ON_USE (connect,
194                      "connect() used without including <sys/socket.h>");
195     _GL_WARN_ON_USE (accept,
196                      "accept() used without including <sys/socket.h>");
197     _GL_WARN_ON_USE (bind,
198                      "bind() used without including <sys/socket.h>");
199     _GL_WARN_ON_USE (getpeername,
200                      "getpeername() used without including <sys/socket.h>");
201     _GL_WARN_ON_USE (getsockname,
202                      "getsockname() used without including <sys/socket.h>");
203     _GL_WARN_ON_USE (getsockopt,
204                      "getsockopt() used without including <sys/socket.h>");
205     _GL_WARN_ON_USE (listen,
206                      "listen() used without including <sys/socket.h>");
207     _GL_WARN_ON_USE (recv,
208                      "recv() used without including <sys/socket.h>");
209     _GL_WARN_ON_USE (send,
210                      "send() used without including <sys/socket.h>");
211     _GL_WARN_ON_USE (recvfrom,
212                      "recvfrom() used without including <sys/socket.h>");
213     _GL_WARN_ON_USE (sendto,
214                      "sendto() used without including <sys/socket.h>");
215     _GL_WARN_ON_USE (setsockopt,
216                      "setsockopt() used without including <sys/socket.h>");
217     _GL_WARN_ON_USE (shutdown,
218                      "shutdown() used without including <sys/socket.h>");
219 #  endif
220 # endif
221 #endif
222
223
224 #if @GNULIB_PSELECT@
225 # if @REPLACE_PSELECT@
226 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
227 #   undef pselect
228 #   define pselect rpl_pselect
229 #  endif
230 _GL_FUNCDECL_RPL (pselect, int,
231                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
232                    struct timespec const *restrict, const sigset_t *restrict));
233 _GL_CXXALIAS_RPL (pselect, int,
234                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
235                    struct timespec const *restrict, const sigset_t *restrict));
236 # else
237 #  if !@HAVE_PSELECT@
238 _GL_FUNCDECL_SYS (pselect, int,
239                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
240                    struct timespec const *restrict, const sigset_t *restrict));
241 #  endif
242 _GL_CXXALIAS_SYS (pselect, int,
243                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
244                    struct timespec const *restrict, const sigset_t *restrict));
245 # endif
246 _GL_CXXALIASWARN (pselect);
247 #elif defined GNULIB_POSIXCHECK
248 # undef pselect
249 # if HAVE_RAW_DECL_PSELECT
250 _GL_WARN_ON_USE (pselect, "pselect is not portable - "
251                  "use gnulib module pselect for portability");
252 # endif
253 #endif
254
255 #if @GNULIB_SELECT@
256 # if @REPLACE_SELECT@
257 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
258 #   undef select
259 #   define select rpl_select
260 #  endif
261 _GL_FUNCDECL_RPL (select, int,
262                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
263 _GL_CXXALIAS_RPL (select, int,
264                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
265 # else
266 _GL_CXXALIAS_SYS (select, int,
267                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
268 # endif
269 _GL_CXXALIASWARN (select);
270 #elif @HAVE_WINSOCK2_H@
271 # undef select
272 # define select select_used_without_requesting_gnulib_module_select
273 #elif defined GNULIB_POSIXCHECK
274 # undef select
275 # if HAVE_RAW_DECL_SELECT
276 _GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
277                  "use gnulib module select for portability");
278 # endif
279 #endif
280
281
282 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
283 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
284 #endif /* OSF/1 */