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