pthread_sigmask: Make declaration C++ safe.
[gnulib.git] / lib / signal.in.h
1 /* A GNU-like <signal.h>.
2
3    Copyright (C) 2006-2011 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
22
23 #if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
24 /* Special invocation convention:
25    - Inside glibc header files.
26    - On glibc systems we have a sequence of nested includes
27      <signal.h> -> <ucontext.h> -> <signal.h>.
28      In this situation, the functions are not yet declared, therefore we cannot
29      provide the C++ aliases.
30    - On glibc systems with GCC 4.3 we have a sequence of nested includes
31      <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
32      In this situation, some of the functions are not yet declared, therefore
33      we cannot provide the C++ aliases.  */
34
35 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
36
37 #else
38 /* Normal invocation convention.  */
39
40 #ifndef _@GUARD_PREFIX@_SIGNAL_H
41
42 #define _GL_ALREADY_INCLUDING_SIGNAL_H
43
44 /* Define pid_t, uid_t.
45    Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
46    On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
47    us; so include <sys/types.h> now, before the second inclusion guard.  */
48 #include <sys/types.h>
49
50 /* The include_next requires a split double-inclusion guard.  */
51 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
52
53 #undef _GL_ALREADY_INCLUDING_SIGNAL_H
54
55 #ifndef _@GUARD_PREFIX@_SIGNAL_H
56 #define _@GUARD_PREFIX@_SIGNAL_H
57
58 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
59
60 /* The definition of _GL_ARG_NONNULL is copied here.  */
61
62 /* The definition of _GL_WARN_ON_USE is copied here.  */
63
64 /* On AIX, sig_atomic_t already includes volatile.  C99 requires that
65    'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
66    Hence, redefine this to a non-volatile type as needed.  */
67 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
68 # if !GNULIB_defined_sig_atomic_t
69 typedef int rpl_sig_atomic_t;
70 #  undef sig_atomic_t
71 #  define sig_atomic_t rpl_sig_atomic_t
72 #  define GNULIB_defined_sig_atomic_t 1
73 # endif
74 #endif
75
76 /* A set or mask of signals.  */
77 #if !@HAVE_SIGSET_T@
78 # if !GNULIB_defined_sigset_t
79 typedef unsigned int sigset_t;
80 #  define GNULIB_defined_sigset_t 1
81 # endif
82 #endif
83
84 /* Define sighandler_t, the type of signal handlers.  A GNU extension.  */
85 #if !@HAVE_SIGHANDLER_T@
86 # ifdef __cplusplus
87 extern "C" {
88 # endif
89 # if !GNULIB_defined_sighandler_t
90 typedef void (*sighandler_t) (int);
91 #  define GNULIB_defined_sighandler_t 1
92 # endif
93 # ifdef __cplusplus
94 }
95 # endif
96 #endif
97
98
99 #if @GNULIB_SIGNAL_H_SIGPIPE@
100 # ifndef SIGPIPE
101 /* Define SIGPIPE to a value that does not overlap with other signals.  */
102 #  define SIGPIPE 13
103 #  define GNULIB_defined_SIGPIPE 1
104 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
105    'write', 'stdio'.  */
106 # endif
107 #endif
108
109
110 /* Maximum signal number + 1.  */
111 #ifndef NSIG
112 # if defined __TANDEM
113 #  define NSIG 32
114 # endif
115 #endif
116
117
118 #if @GNULIB_PTHREAD_SIGMASK@
119 # if !@HAVE_PTHREAD_SIGMASK@
120 _GL_FUNCDECL_SYS (pthread_sigmask, int,
121                   (int how, const sigset_t *new_mask, sigset_t *old_mask));
122 # endif
123 _GL_CXXALIAS_SYS (pthread_sigmask, int,
124                   (int how, const sigset_t *new_mask, sigset_t *old_mask));
125 _GL_CXXALIASWARN (pthread_sigmask);
126 #elif defined GNULIB_POSIXCHECK
127 # undef pthread_sigmask
128 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
129 _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
130                  "use gnulib module pthread_sigmask for portability");
131 # endif
132 #endif
133
134
135 #if @GNULIB_SIGPROCMASK@
136 # if !@HAVE_POSIX_SIGNALBLOCKING@
137
138 /* Maximum signal number + 1.  */
139 #  ifndef NSIG
140 #   define NSIG 32
141 #  endif
142
143 /* This code supports only 32 signals.  */
144 #  if !GNULIB_defined_verify_NSIG_constraint
145 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
146 #   define GNULIB_defined_verify_NSIG_constraint 1
147 #  endif
148
149 # endif
150
151 /* Test whether a given signal is contained in a signal set.  */
152 # if @HAVE_POSIX_SIGNALBLOCKING@
153 /* This function is defined as a macro on MacOS X.  */
154 #  if defined __cplusplus && defined GNULIB_NAMESPACE
155 #   undef sigismember
156 #  endif
157 # else
158 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
159                                     _GL_ARG_NONNULL ((1)));
160 # endif
161 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
162 _GL_CXXALIASWARN (sigismember);
163
164 /* Initialize a signal set to the empty set.  */
165 # if @HAVE_POSIX_SIGNALBLOCKING@
166 /* This function is defined as a macro on MacOS X.  */
167 #  if defined __cplusplus && defined GNULIB_NAMESPACE
168 #   undef sigemptyset
169 #  endif
170 # else
171 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
172 # endif
173 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
174 _GL_CXXALIASWARN (sigemptyset);
175
176 /* Add a signal to a signal set.  */
177 # if @HAVE_POSIX_SIGNALBLOCKING@
178 /* This function is defined as a macro on MacOS X.  */
179 #  if defined __cplusplus && defined GNULIB_NAMESPACE
180 #   undef sigaddset
181 #  endif
182 # else
183 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
184                                   _GL_ARG_NONNULL ((1)));
185 # endif
186 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
187 _GL_CXXALIASWARN (sigaddset);
188
189 /* Remove a signal from a signal set.  */
190 # if @HAVE_POSIX_SIGNALBLOCKING@
191 /* This function is defined as a macro on MacOS X.  */
192 #  if defined __cplusplus && defined GNULIB_NAMESPACE
193 #   undef sigdelset
194 #  endif
195 # else
196 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
197                                   _GL_ARG_NONNULL ((1)));
198 # endif
199 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
200 _GL_CXXALIASWARN (sigdelset);
201
202 /* Fill a signal set with all possible signals.  */
203 # if @HAVE_POSIX_SIGNALBLOCKING@
204 /* This function is defined as a macro on MacOS X.  */
205 #  if defined __cplusplus && defined GNULIB_NAMESPACE
206 #   undef sigfillset
207 #  endif
208 # else
209 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
210 # endif
211 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
212 _GL_CXXALIASWARN (sigfillset);
213
214 /* Return the set of those blocked signals that are pending.  */
215 # if !@HAVE_POSIX_SIGNALBLOCKING@
216 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
217 # endif
218 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
219 _GL_CXXALIASWARN (sigpending);
220
221 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
222    Then, if SET is not NULL, affect the current set of blocked signals by
223    combining it with *SET as indicated in OPERATION.
224    In this implementation, you are not allowed to change a signal handler
225    while the signal is blocked.  */
226 # if !@HAVE_POSIX_SIGNALBLOCKING@
227 #  define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
228 #  define SIG_SETMASK 1  /* blocked_set = *set; */
229 #  define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
230 _GL_FUNCDECL_SYS (sigprocmask, int,
231                   (int operation, const sigset_t *set, sigset_t *old_set));
232 # endif
233 _GL_CXXALIAS_SYS (sigprocmask, int,
234                   (int operation, const sigset_t *set, sigset_t *old_set));
235 _GL_CXXALIASWARN (sigprocmask);
236
237 /* Install the handler FUNC for signal SIG, and return the previous
238    handler.  */
239 # ifdef __cplusplus
240 extern "C" {
241 # endif
242 # if !GNULIB_defined_function_taking_int_returning_void_t
243 typedef void (*_gl_function_taking_int_returning_void_t) (int);
244 #  define GNULIB_defined_function_taking_int_returning_void_t 1
245 # endif
246 # ifdef __cplusplus
247 }
248 # endif
249 # if !@HAVE_POSIX_SIGNALBLOCKING@
250 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
251 #   define signal rpl_signal
252 #  endif
253 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
254                   (int sig, _gl_function_taking_int_returning_void_t func));
255 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
256                   (int sig, _gl_function_taking_int_returning_void_t func));
257 # else
258 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
259                   (int sig, _gl_function_taking_int_returning_void_t func));
260 # endif
261 _GL_CXXALIASWARN (signal);
262
263 /* Raise signal SIG.  */
264 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
265 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
266 #   undef raise
267 #   define raise rpl_raise
268 #  endif
269 _GL_FUNCDECL_RPL (raise, int, (int sig));
270 _GL_CXXALIAS_RPL (raise, int, (int sig));
271 # else
272 _GL_CXXALIAS_SYS (raise, int, (int sig));
273 # endif
274 _GL_CXXALIASWARN (raise);
275
276 #elif defined GNULIB_POSIXCHECK
277 # undef sigaddset
278 # if HAVE_RAW_DECL_SIGADDSET
279 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
280                  "use the gnulib module sigprocmask for portability");
281 # endif
282 # undef sigdelset
283 # if HAVE_RAW_DECL_SIGDELSET
284 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
285                  "use the gnulib module sigprocmask for portability");
286 # endif
287 # undef sigemptyset
288 # if HAVE_RAW_DECL_SIGEMPTYSET
289 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
290                  "use the gnulib module sigprocmask for portability");
291 # endif
292 # undef sigfillset
293 # if HAVE_RAW_DECL_SIGFILLSET
294 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
295                  "use the gnulib module sigprocmask for portability");
296 # endif
297 # undef sigismember
298 # if HAVE_RAW_DECL_SIGISMEMBER
299 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
300                  "use the gnulib module sigprocmask for portability");
301 # endif
302 # undef sigpending
303 # if HAVE_RAW_DECL_SIGPENDING
304 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
305                  "use the gnulib module sigprocmask for portability");
306 # endif
307 # undef sigprocmask
308 # if HAVE_RAW_DECL_SIGPROCMASK
309 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
310                  "use the gnulib module sigprocmask for portability");
311 # endif
312 #endif /* @GNULIB_SIGPROCMASK@ */
313
314
315 #if @GNULIB_SIGACTION@
316 # if !@HAVE_SIGACTION@
317
318 #  if !@HAVE_SIGINFO_T@
319
320 #   if !GNULIB_defined_siginfo_types
321
322 /* Present to allow compilation, but unsupported by gnulib.  */
323 union sigval
324 {
325   int sival_int;
326   void *sival_ptr;
327 };
328
329 /* Present to allow compilation, but unsupported by gnulib.  */
330 struct siginfo_t
331 {
332   int si_signo;
333   int si_code;
334   int si_errno;
335   pid_t si_pid;
336   uid_t si_uid;
337   void *si_addr;
338   int si_status;
339   long si_band;
340   union sigval si_value;
341 };
342 typedef struct siginfo_t siginfo_t;
343
344 #    define GNULIB_defined_siginfo_types 1
345 #   endif
346
347 #  endif /* !@HAVE_SIGINFO_T@ */
348
349 /* We assume that platforms which lack the sigaction() function also lack
350    the 'struct sigaction' type, and vice versa.  */
351
352 #  if !GNULIB_defined_struct_sigaction
353
354 struct sigaction
355 {
356   union
357   {
358     void (*_sa_handler) (int);
359     /* Present to allow compilation, but unsupported by gnulib.  POSIX
360        says that implementations may, but not must, make sa_sigaction
361        overlap with sa_handler, but we know of no implementation where
362        they do not overlap.  */
363     void (*_sa_sigaction) (int, siginfo_t *, void *);
364   } _sa_func;
365   sigset_t sa_mask;
366   /* Not all POSIX flags are supported.  */
367   int sa_flags;
368 };
369 #   define sa_handler _sa_func._sa_handler
370 #   define sa_sigaction _sa_func._sa_sigaction
371 /* Unsupported flags are not present.  */
372 #   define SA_RESETHAND 1
373 #   define SA_NODEFER 2
374 #   define SA_RESTART 4
375
376 #   define GNULIB_defined_struct_sigaction 1
377 #  endif
378
379 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
380                                    struct sigaction *restrict));
381
382 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
383
384 #  define sa_sigaction sa_handler
385
386 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
387
388 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
389                                    struct sigaction *restrict));
390 _GL_CXXALIASWARN (sigaction);
391
392 #elif defined GNULIB_POSIXCHECK
393 # undef sigaction
394 # if HAVE_RAW_DECL_SIGACTION
395 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
396                  "use the gnulib module sigaction for portability");
397 # endif
398 #endif
399
400 /* Some systems don't have SA_NODEFER.  */
401 #ifndef SA_NODEFER
402 # define SA_NODEFER 0
403 #endif
404
405
406 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
407 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
408 #endif