Merge commit 'b572c3a256e7bf1e4eecc8c36448c08093240a6a' into stable
[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    Get the close() declaration before we override it.  */
100 # if @HAVE_WINSOCK2_H@
101 #  if !defined _GL_INCLUDING_WINSOCK2_H
102 #   define _GL_INCLUDING_WINSOCK2_H
103 #   include <winsock2.h>
104 #   undef _GL_INCLUDING_WINSOCK2_H
105 #  endif
106 #  include <io.h>
107 # endif
108 #endif
109
110 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
111
112 /* The definition of _GL_WARN_ON_USE is copied here.  */
113
114
115 /* Fix some definitions from <winsock2.h>.  */
116
117 #if @HAVE_WINSOCK2_H@
118
119 # if !GNULIB_defined_rpl_fd_isset
120
121 /* Re-define FD_ISSET to avoid a WSA call while we are not using
122    network sockets.  */
123 static inline int
124 rpl_fd_isset (SOCKET fd, fd_set * set)
125 {
126   u_int i;
127   if (set == NULL)
128     return 0;
129
130   for (i = 0; i < set->fd_count; i++)
131     if (set->fd_array[i] == fd)
132       return 1;
133
134   return 0;
135 }
136
137 #  define GNULIB_defined_rpl_fd_isset 1
138 # endif
139
140 # undef FD_ISSET
141 # define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
142
143 #endif
144
145 /* Hide some function declarations from <winsock2.h>.  */
146
147 #if @HAVE_WINSOCK2_H@
148 # if !defined _@GUARD_PREFIX@_UNISTD_H
149 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
150 #   undef close
151 #   define close close_used_without_including_unistd_h
152 #  else
153     _GL_WARN_ON_USE (close,
154                      "close() used without including <unistd.h>");
155 #  endif
156 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
157 #   undef gethostname
158 #   define gethostname gethostname_used_without_including_unistd_h
159 #  else
160     _GL_WARN_ON_USE (gethostname,
161                      "gethostname() used without including <unistd.h>");
162 #  endif
163 # endif
164 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
165 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
166 #   undef socket
167 #   define socket              socket_used_without_including_sys_socket_h
168 #   undef connect
169 #   define connect             connect_used_without_including_sys_socket_h
170 #   undef accept
171 #   define accept              accept_used_without_including_sys_socket_h
172 #   undef bind
173 #   define bind                bind_used_without_including_sys_socket_h
174 #   undef getpeername
175 #   define getpeername         getpeername_used_without_including_sys_socket_h
176 #   undef getsockname
177 #   define getsockname         getsockname_used_without_including_sys_socket_h
178 #   undef getsockopt
179 #   define getsockopt          getsockopt_used_without_including_sys_socket_h
180 #   undef listen
181 #   define listen              listen_used_without_including_sys_socket_h
182 #   undef recv
183 #   define recv                recv_used_without_including_sys_socket_h
184 #   undef send
185 #   define send                send_used_without_including_sys_socket_h
186 #   undef recvfrom
187 #   define recvfrom            recvfrom_used_without_including_sys_socket_h
188 #   undef sendto
189 #   define sendto              sendto_used_without_including_sys_socket_h
190 #   undef setsockopt
191 #   define setsockopt          setsockopt_used_without_including_sys_socket_h
192 #   undef shutdown
193 #   define shutdown            shutdown_used_without_including_sys_socket_h
194 #  else
195     _GL_WARN_ON_USE (socket,
196                      "socket() used without including <sys/socket.h>");
197     _GL_WARN_ON_USE (connect,
198                      "connect() used without including <sys/socket.h>");
199     _GL_WARN_ON_USE (accept,
200                      "accept() used without including <sys/socket.h>");
201     _GL_WARN_ON_USE (bind,
202                      "bind() used without including <sys/socket.h>");
203     _GL_WARN_ON_USE (getpeername,
204                      "getpeername() used without including <sys/socket.h>");
205     _GL_WARN_ON_USE (getsockname,
206                      "getsockname() used without including <sys/socket.h>");
207     _GL_WARN_ON_USE (getsockopt,
208                      "getsockopt() used without including <sys/socket.h>");
209     _GL_WARN_ON_USE (listen,
210                      "listen() used without including <sys/socket.h>");
211     _GL_WARN_ON_USE (recv,
212                      "recv() used without including <sys/socket.h>");
213     _GL_WARN_ON_USE (send,
214                      "send() used without including <sys/socket.h>");
215     _GL_WARN_ON_USE (recvfrom,
216                      "recvfrom() used without including <sys/socket.h>");
217     _GL_WARN_ON_USE (sendto,
218                      "sendto() used without including <sys/socket.h>");
219     _GL_WARN_ON_USE (setsockopt,
220                      "setsockopt() used without including <sys/socket.h>");
221     _GL_WARN_ON_USE (shutdown,
222                      "shutdown() used without including <sys/socket.h>");
223 #  endif
224 # endif
225 #endif
226
227
228 #if @GNULIB_PSELECT@
229 # if @REPLACE_PSELECT@
230 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
231 #   undef pselect
232 #   define pselect rpl_pselect
233 #  endif
234 _GL_FUNCDECL_RPL (pselect, int,
235                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
236                    struct timespec const *restrict, const sigset_t *restrict));
237 _GL_CXXALIAS_RPL (pselect, int,
238                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
239                    struct timespec const *restrict, const sigset_t *restrict));
240 # else
241 #  if !@HAVE_PSELECT@
242 _GL_FUNCDECL_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_CXXALIAS_SYS (pselect, int,
247                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
248                    struct timespec const *restrict, const sigset_t *restrict));
249 # endif
250 _GL_CXXALIASWARN (pselect);
251 #elif defined GNULIB_POSIXCHECK
252 # undef pselect
253 # if HAVE_RAW_DECL_PSELECT
254 _GL_WARN_ON_USE (pselect, "pselect is not portable - "
255                  "use gnulib module pselect for portability");
256 # endif
257 #endif
258
259 #if @GNULIB_SELECT@
260 # if @REPLACE_SELECT@
261 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
262 #   undef select
263 #   define select rpl_select
264 #  endif
265 _GL_FUNCDECL_RPL (select, int,
266                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
267 _GL_CXXALIAS_RPL (select, int,
268                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
269 # else
270 _GL_CXXALIAS_SYS (select, int,
271                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
272 # endif
273 _GL_CXXALIASWARN (select);
274 #elif @HAVE_WINSOCK2_H@
275 # undef select
276 # define select select_used_without_requesting_gnulib_module_select
277 #elif defined GNULIB_POSIXCHECK
278 # undef select
279 # if HAVE_RAW_DECL_SELECT
280 _GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
281                  "use gnulib module select for portability");
282 # endif
283 #endif
284
285
286 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
287 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
288 #endif /* OSF/1 */