Bug#16045
[emacs.git] / lib / signal.in.h
bloba531487e355f42db44af7d062d0564b9a09ff265
1 /* A GNU-like <signal.h>.
3 Copyright (C) 2006-2013 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
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. */
35 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
37 #else
38 /* Normal invocation convention. */
40 #ifndef _@GUARD_PREFIX@_SIGNAL_H
42 #define _GL_ALREADY_INCLUDING_SIGNAL_H
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>
50 /* The include_next requires a split double-inclusion guard. */
51 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
53 #undef _GL_ALREADY_INCLUDING_SIGNAL_H
55 #ifndef _@GUARD_PREFIX@_SIGNAL_H
56 #define _@GUARD_PREFIX@_SIGNAL_H
58 /* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare
59 pthread_sigmask in <pthread.h>, not in <signal.h>.
60 But avoid namespace pollution on glibc systems.*/
61 #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
62 && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ || defined __sun) \
63 && ! defined __GLIBC__
64 # include <pthread.h>
65 #endif
67 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
69 /* The definition of _GL_ARG_NONNULL is copied here. */
71 /* The definition of _GL_WARN_ON_USE is copied here. */
73 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
74 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
75 Hence, redefine this to a non-volatile type as needed. */
76 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
77 # if !GNULIB_defined_sig_atomic_t
78 typedef int rpl_sig_atomic_t;
79 # undef sig_atomic_t
80 # define sig_atomic_t rpl_sig_atomic_t
81 # define GNULIB_defined_sig_atomic_t 1
82 # endif
83 #endif
85 /* A set or mask of signals. */
86 #if !@HAVE_SIGSET_T@
87 # if !GNULIB_defined_sigset_t
88 typedef unsigned int sigset_t;
89 # define GNULIB_defined_sigset_t 1
90 # endif
91 #endif
93 /* Define sighandler_t, the type of signal handlers. A GNU extension. */
94 #if !@HAVE_SIGHANDLER_T@
95 # ifdef __cplusplus
96 extern "C" {
97 # endif
98 # if !GNULIB_defined_sighandler_t
99 typedef void (*sighandler_t) (int);
100 # define GNULIB_defined_sighandler_t 1
101 # endif
102 # ifdef __cplusplus
104 # endif
105 #endif
108 #if @GNULIB_SIGNAL_H_SIGPIPE@
109 # ifndef SIGPIPE
110 /* Define SIGPIPE to a value that does not overlap with other signals. */
111 # define SIGPIPE 13
112 # define GNULIB_defined_SIGPIPE 1
113 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
114 'write', 'stdio'. */
115 # endif
116 #endif
119 /* Maximum signal number + 1. */
120 #ifndef NSIG
121 # if defined __TANDEM
122 # define NSIG 32
123 # endif
124 #endif
127 #if @GNULIB_PTHREAD_SIGMASK@
128 # if @REPLACE_PTHREAD_SIGMASK@
129 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
130 # undef pthread_sigmask
131 # define pthread_sigmask rpl_pthread_sigmask
132 # endif
133 _GL_FUNCDECL_RPL (pthread_sigmask, int,
134 (int how, const sigset_t *new_mask, sigset_t *old_mask));
135 _GL_CXXALIAS_RPL (pthread_sigmask, int,
136 (int how, const sigset_t *new_mask, sigset_t *old_mask));
137 # else
138 # if !@HAVE_PTHREAD_SIGMASK@
139 _GL_FUNCDECL_SYS (pthread_sigmask, int,
140 (int how, const sigset_t *new_mask, sigset_t *old_mask));
141 # endif
142 _GL_CXXALIAS_SYS (pthread_sigmask, int,
143 (int how, const sigset_t *new_mask, sigset_t *old_mask));
144 # endif
145 _GL_CXXALIASWARN (pthread_sigmask);
146 #elif defined GNULIB_POSIXCHECK
147 # undef pthread_sigmask
148 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
149 _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
150 "use gnulib module pthread_sigmask for portability");
151 # endif
152 #endif
155 #if @GNULIB_RAISE@
156 # if @REPLACE_RAISE@
157 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
158 # undef raise
159 # define raise rpl_raise
160 # endif
161 _GL_FUNCDECL_RPL (raise, int, (int sig));
162 _GL_CXXALIAS_RPL (raise, int, (int sig));
163 # else
164 # if !@HAVE_RAISE@
165 _GL_FUNCDECL_SYS (raise, int, (int sig));
166 # endif
167 _GL_CXXALIAS_SYS (raise, int, (int sig));
168 # endif
169 _GL_CXXALIASWARN (raise);
170 #elif defined GNULIB_POSIXCHECK
171 # undef raise
172 /* Assume raise is always declared. */
173 _GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
174 "use gnulib module raise for portability");
175 #endif
178 #if @GNULIB_SIGPROCMASK@
179 # if !@HAVE_POSIX_SIGNALBLOCKING@
181 # ifndef GNULIB_defined_signal_blocking
182 # define GNULIB_defined_signal_blocking 1
183 # endif
185 /* Maximum signal number + 1. */
186 # ifndef NSIG
187 # define NSIG 32
188 # endif
190 /* This code supports only 32 signals. */
191 # if !GNULIB_defined_verify_NSIG_constraint
192 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
193 # define GNULIB_defined_verify_NSIG_constraint 1
194 # endif
196 # endif
198 /* When also using extern inline, suppress the use of static inline in
199 standard headers of problematic Apple configurations, as Libc at
200 least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
201 <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
202 Perhaps Apple will fix this some day. */
203 #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
204 && (defined __i386__ || defined __x86_64__))
205 # undef sigaddset
206 # undef sigdelset
207 # undef sigemptyset
208 # undef sigfillset
209 # undef sigismember
210 #endif
212 /* Test whether a given signal is contained in a signal set. */
213 # if @HAVE_POSIX_SIGNALBLOCKING@
214 /* This function is defined as a macro on Mac OS X. */
215 # if defined __cplusplus && defined GNULIB_NAMESPACE
216 # undef sigismember
217 # endif
218 # else
219 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
220 _GL_ARG_NONNULL ((1)));
221 # endif
222 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
223 _GL_CXXALIASWARN (sigismember);
225 /* Initialize a signal set to the empty set. */
226 # if @HAVE_POSIX_SIGNALBLOCKING@
227 /* This function is defined as a macro on Mac OS X. */
228 # if defined __cplusplus && defined GNULIB_NAMESPACE
229 # undef sigemptyset
230 # endif
231 # else
232 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
233 # endif
234 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
235 _GL_CXXALIASWARN (sigemptyset);
237 /* Add a signal to a signal set. */
238 # if @HAVE_POSIX_SIGNALBLOCKING@
239 /* This function is defined as a macro on Mac OS X. */
240 # if defined __cplusplus && defined GNULIB_NAMESPACE
241 # undef sigaddset
242 # endif
243 # else
244 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
245 _GL_ARG_NONNULL ((1)));
246 # endif
247 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
248 _GL_CXXALIASWARN (sigaddset);
250 /* Remove a signal from a signal set. */
251 # if @HAVE_POSIX_SIGNALBLOCKING@
252 /* This function is defined as a macro on Mac OS X. */
253 # if defined __cplusplus && defined GNULIB_NAMESPACE
254 # undef sigdelset
255 # endif
256 # else
257 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
258 _GL_ARG_NONNULL ((1)));
259 # endif
260 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
261 _GL_CXXALIASWARN (sigdelset);
263 /* Fill a signal set with all possible signals. */
264 # if @HAVE_POSIX_SIGNALBLOCKING@
265 /* This function is defined as a macro on Mac OS X. */
266 # if defined __cplusplus && defined GNULIB_NAMESPACE
267 # undef sigfillset
268 # endif
269 # else
270 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
271 # endif
272 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
273 _GL_CXXALIASWARN (sigfillset);
275 /* Return the set of those blocked signals that are pending. */
276 # if !@HAVE_POSIX_SIGNALBLOCKING@
277 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
278 # endif
279 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
280 _GL_CXXALIASWARN (sigpending);
282 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
283 Then, if SET is not NULL, affect the current set of blocked signals by
284 combining it with *SET as indicated in OPERATION.
285 In this implementation, you are not allowed to change a signal handler
286 while the signal is blocked. */
287 # if !@HAVE_POSIX_SIGNALBLOCKING@
288 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
289 # define SIG_SETMASK 1 /* blocked_set = *set; */
290 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
291 _GL_FUNCDECL_SYS (sigprocmask, int,
292 (int operation, const sigset_t *set, sigset_t *old_set));
293 # endif
294 _GL_CXXALIAS_SYS (sigprocmask, int,
295 (int operation, const sigset_t *set, sigset_t *old_set));
296 _GL_CXXALIASWARN (sigprocmask);
298 /* Install the handler FUNC for signal SIG, and return the previous
299 handler. */
300 # ifdef __cplusplus
301 extern "C" {
302 # endif
303 # if !GNULIB_defined_function_taking_int_returning_void_t
304 typedef void (*_gl_function_taking_int_returning_void_t) (int);
305 # define GNULIB_defined_function_taking_int_returning_void_t 1
306 # endif
307 # ifdef __cplusplus
309 # endif
310 # if !@HAVE_POSIX_SIGNALBLOCKING@
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312 # define signal rpl_signal
313 # endif
314 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
315 (int sig, _gl_function_taking_int_returning_void_t func));
316 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
317 (int sig, _gl_function_taking_int_returning_void_t func));
318 # else
319 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
320 (int sig, _gl_function_taking_int_returning_void_t func));
321 # endif
322 _GL_CXXALIASWARN (signal);
324 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
325 /* Raise signal SIGPIPE. */
326 _GL_EXTERN_C int _gl_raise_SIGPIPE (void);
327 # endif
329 #elif defined GNULIB_POSIXCHECK
330 # undef sigaddset
331 # if HAVE_RAW_DECL_SIGADDSET
332 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
333 "use the gnulib module sigprocmask for portability");
334 # endif
335 # undef sigdelset
336 # if HAVE_RAW_DECL_SIGDELSET
337 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
338 "use the gnulib module sigprocmask for portability");
339 # endif
340 # undef sigemptyset
341 # if HAVE_RAW_DECL_SIGEMPTYSET
342 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
343 "use the gnulib module sigprocmask for portability");
344 # endif
345 # undef sigfillset
346 # if HAVE_RAW_DECL_SIGFILLSET
347 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
348 "use the gnulib module sigprocmask for portability");
349 # endif
350 # undef sigismember
351 # if HAVE_RAW_DECL_SIGISMEMBER
352 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
353 "use the gnulib module sigprocmask for portability");
354 # endif
355 # undef sigpending
356 # if HAVE_RAW_DECL_SIGPENDING
357 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
358 "use the gnulib module sigprocmask for portability");
359 # endif
360 # undef sigprocmask
361 # if HAVE_RAW_DECL_SIGPROCMASK
362 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
363 "use the gnulib module sigprocmask for portability");
364 # endif
365 #endif /* @GNULIB_SIGPROCMASK@ */
368 #if @GNULIB_SIGACTION@
369 # if !@HAVE_SIGACTION@
371 # if !@HAVE_SIGINFO_T@
373 # if !GNULIB_defined_siginfo_types
375 /* Present to allow compilation, but unsupported by gnulib. */
376 union sigval
378 int sival_int;
379 void *sival_ptr;
382 /* Present to allow compilation, but unsupported by gnulib. */
383 struct siginfo_t
385 int si_signo;
386 int si_code;
387 int si_errno;
388 pid_t si_pid;
389 uid_t si_uid;
390 void *si_addr;
391 int si_status;
392 long si_band;
393 union sigval si_value;
395 typedef struct siginfo_t siginfo_t;
397 # define GNULIB_defined_siginfo_types 1
398 # endif
400 # endif /* !@HAVE_SIGINFO_T@ */
402 /* We assume that platforms which lack the sigaction() function also lack
403 the 'struct sigaction' type, and vice versa. */
405 # if !GNULIB_defined_struct_sigaction
407 struct sigaction
409 union
411 void (*_sa_handler) (int);
412 /* Present to allow compilation, but unsupported by gnulib. POSIX
413 says that implementations may, but not must, make sa_sigaction
414 overlap with sa_handler, but we know of no implementation where
415 they do not overlap. */
416 void (*_sa_sigaction) (int, siginfo_t *, void *);
417 } _sa_func;
418 sigset_t sa_mask;
419 /* Not all POSIX flags are supported. */
420 int sa_flags;
422 # define sa_handler _sa_func._sa_handler
423 # define sa_sigaction _sa_func._sa_sigaction
424 /* Unsupported flags are not present. */
425 # define SA_RESETHAND 1
426 # define SA_NODEFER 2
427 # define SA_RESTART 4
429 # define GNULIB_defined_struct_sigaction 1
430 # endif
432 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
433 struct sigaction *restrict));
435 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
437 # define sa_sigaction sa_handler
439 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
441 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
442 struct sigaction *restrict));
443 _GL_CXXALIASWARN (sigaction);
445 #elif defined GNULIB_POSIXCHECK
446 # undef sigaction
447 # if HAVE_RAW_DECL_SIGACTION
448 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
449 "use the gnulib module sigaction for portability");
450 # endif
451 #endif
453 /* Some systems don't have SA_NODEFER. */
454 #ifndef SA_NODEFER
455 # define SA_NODEFER 0
456 #endif
459 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
460 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
461 #endif