sys_select: define sigset_t more portably
[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.  Also, gnulib's <sys/socket.h> redefines select
89    so as to hide the declaration from <winsock2.h>.  */
90 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
91 #  include <sys/socket.h>
92 # endif
93 #endif
94
95 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
96
97 /* The definition of _GL_WARN_ON_USE is copied here.  */
98
99
100 #if @GNULIB_PSELECT@
101 # if @REPLACE_PSELECT@
102 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
103 #   undef pselect
104 #   define pselect rpl_pselect
105 #  endif
106 _GL_FUNCDECL_RPL (pselect, int,
107                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
108                    struct timespec const *restrict, const sigset_t *restrict));
109 _GL_CXXALIAS_RPL (pselect, int,
110                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
111                    struct timespec const *restrict, const sigset_t *restrict));
112 # else
113 #  if !@HAVE_PSELECT@
114 _GL_FUNCDECL_SYS (pselect, int,
115                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
116                    struct timespec const *restrict, const sigset_t *restrict));
117 #  endif
118 _GL_CXXALIAS_SYS (pselect, int,
119                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
120                    struct timespec const *restrict, const sigset_t *restrict));
121 # endif
122 _GL_CXXALIASWARN (pselect);
123 #elif defined GNULIB_POSIXCHECK
124 # undef pselect
125 # if HAVE_RAW_DECL_PSELECT
126 _GL_WARN_ON_USE (pselect, "pselect is not portable - "
127                  "use gnulib module pselect for portability");
128 # endif
129 #endif
130
131 #if @GNULIB_SELECT@
132 # if @REPLACE_SELECT@
133 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
134 #   undef select
135 #   define select rpl_select
136 #  endif
137 _GL_FUNCDECL_RPL (select, int,
138                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
139 _GL_CXXALIAS_RPL (select, int,
140                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
141 # else
142 _GL_CXXALIAS_SYS (select, int,
143                   (int, fd_set *, fd_set *, fd_set *, struct timeval *));
144 # endif
145 _GL_CXXALIASWARN (select);
146 #elif @HAVE_WINSOCK2_H@
147 # undef select
148 # define select select_used_without_requesting_gnulib_module_select
149 #elif defined GNULIB_POSIXCHECK
150 # undef select
151 # if HAVE_RAW_DECL_SELECT
152 _GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
153                  "use gnulib module select for portability");
154 # endif
155 #endif
156
157
158 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
159 #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
160 #endif /* OSF/1 */