sys_select.in.h 12 KB

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