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