1 /* A GNU-like <signal.h>.
3 Copyright (C) 2006-2011 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/>. */
19 @PRAGMA_SYSTEM_HEADER@
23 #if defined __need_sig_atomic_t || defined __need_sigset_t
24 /* Special invocation convention inside glibc header files. */
26 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
29 /* Normal invocation convention. */
31 #ifndef _@GUARD_PREFIX@_SIGNAL_H
33 /* Define pid_t, uid_t.
34 Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
35 On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
36 us; so include <sys/types.h> now, before the second inclusion guard. */
37 #include <sys/types.h>
39 /* The include_next requires a split double-inclusion guard. */
40 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
42 #ifndef _@GUARD_PREFIX@_SIGNAL_H
43 #define _@GUARD_PREFIX@_SIGNAL_H
45 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
47 /* The definition of _GL_ARG_NONNULL is copied here. */
49 /* The definition of _GL_WARN_ON_USE is copied here. */
51 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
52 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
53 Hence, redefine this to a non-volatile type as needed. */
54 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
55 # if !GNULIB_defined_sig_atomic_t
56 typedef int rpl_sig_atomic_t;
58 # define sig_atomic_t rpl_sig_atomic_t
59 # define GNULIB_defined_sig_atomic_t 1
63 /* A set or mask of signals. */
65 # if !GNULIB_defined_sigset_t
66 typedef unsigned int sigset_t;
67 # define GNULIB_defined_sigset_t 1
71 /* Define sighandler_t, the type of signal handlers. A GNU extension. */
72 #if !@HAVE_SIGHANDLER_T@
76 # if !GNULIB_defined_sighandler_t
77 typedef void (*sighandler_t) (int);
78 # define GNULIB_defined_sighandler_t 1
86 #if @GNULIB_SIGNAL_H_SIGPIPE@
88 /* Define SIGPIPE to a value that does not overlap with other signals. */
90 # define GNULIB_defined_SIGPIPE 1
91 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
97 /* Maximum signal number + 1. */
105 #if @GNULIB_PTHREAD_SIGMASK@
106 # if @REPLACE_PTHREAD_SIGMASK@
107 # undef pthread_sigmask
108 # define pthread_sigmask sigprocmask
110 #elif defined GNULIB_POSIXCHECK
111 # undef pthread_sigmask
112 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
113 _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
114 "use gnulib module pthread_sigmask for portability");
119 #if @GNULIB_SIGPROCMASK@
120 # if !@HAVE_POSIX_SIGNALBLOCKING@
122 /* Maximum signal number + 1. */
127 /* This code supports only 32 signals. */
128 # if !GNULIB_defined_verify_NSIG_constraint
129 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
130 # define GNULIB_defined_verify_NSIG_constraint 1
135 /* Test whether a given signal is contained in a signal set. */
136 # if @HAVE_POSIX_SIGNALBLOCKING@
137 /* This function is defined as a macro on MacOS X. */
138 # if defined __cplusplus && defined GNULIB_NAMESPACE
142 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
143 _GL_ARG_NONNULL ((1)));
145 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
146 _GL_CXXALIASWARN (sigismember);
148 /* Initialize a signal set to the empty set. */
149 # if @HAVE_POSIX_SIGNALBLOCKING@
150 /* This function is defined as a macro on MacOS X. */
151 # if defined __cplusplus && defined GNULIB_NAMESPACE
155 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
157 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
158 _GL_CXXALIASWARN (sigemptyset);
160 /* Add a signal to a signal set. */
161 # if @HAVE_POSIX_SIGNALBLOCKING@
162 /* This function is defined as a macro on MacOS X. */
163 # if defined __cplusplus && defined GNULIB_NAMESPACE
167 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
168 _GL_ARG_NONNULL ((1)));
170 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
171 _GL_CXXALIASWARN (sigaddset);
173 /* Remove a signal from a signal set. */
174 # if @HAVE_POSIX_SIGNALBLOCKING@
175 /* This function is defined as a macro on MacOS X. */
176 # if defined __cplusplus && defined GNULIB_NAMESPACE
180 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
181 _GL_ARG_NONNULL ((1)));
183 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
184 _GL_CXXALIASWARN (sigdelset);
186 /* Fill a signal set with all possible signals. */
187 # if @HAVE_POSIX_SIGNALBLOCKING@
188 /* This function is defined as a macro on MacOS X. */
189 # if defined __cplusplus && defined GNULIB_NAMESPACE
193 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
195 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
196 _GL_CXXALIASWARN (sigfillset);
198 /* Return the set of those blocked signals that are pending. */
199 # if !@HAVE_POSIX_SIGNALBLOCKING@
200 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
202 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
203 _GL_CXXALIASWARN (sigpending);
205 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
206 Then, if SET is not NULL, affect the current set of blocked signals by
207 combining it with *SET as indicated in OPERATION.
208 In this implementation, you are not allowed to change a signal handler
209 while the signal is blocked. */
210 # if !@HAVE_POSIX_SIGNALBLOCKING@
211 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
212 # define SIG_SETMASK 1 /* blocked_set = *set; */
213 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
214 _GL_FUNCDECL_SYS (sigprocmask, int,
215 (int operation, const sigset_t *set, sigset_t *old_set));
217 _GL_CXXALIAS_SYS (sigprocmask, int,
218 (int operation, const sigset_t *set, sigset_t *old_set));
219 _GL_CXXALIASWARN (sigprocmask);
221 /* Install the handler FUNC for signal SIG, and return the previous
226 # if !GNULIB_defined_function_taking_int_returning_void_t
227 typedef void (*_gl_function_taking_int_returning_void_t) (int);
228 # define GNULIB_defined_function_taking_int_returning_void_t 1
233 # if !@HAVE_POSIX_SIGNALBLOCKING@
234 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
235 # define signal rpl_signal
237 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
238 (int sig, _gl_function_taking_int_returning_void_t func));
239 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
240 (int sig, _gl_function_taking_int_returning_void_t func));
242 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
243 (int sig, _gl_function_taking_int_returning_void_t func));
245 _GL_CXXALIASWARN (signal);
247 /* Raise signal SIG. */
248 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
249 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
251 # define raise rpl_raise
253 _GL_FUNCDECL_RPL (raise, int, (int sig));
254 _GL_CXXALIAS_RPL (raise, int, (int sig));
256 _GL_CXXALIAS_SYS (raise, int, (int sig));
258 _GL_CXXALIASWARN (raise);
260 #elif defined GNULIB_POSIXCHECK
262 # if HAVE_RAW_DECL_SIGADDSET
263 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
264 "use the gnulib module sigprocmask for portability");
267 # if HAVE_RAW_DECL_SIGDELSET
268 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
269 "use the gnulib module sigprocmask for portability");
272 # if HAVE_RAW_DECL_SIGEMPTYSET
273 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
274 "use the gnulib module sigprocmask for portability");
277 # if HAVE_RAW_DECL_SIGFILLSET
278 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
279 "use the gnulib module sigprocmask for portability");
282 # if HAVE_RAW_DECL_SIGISMEMBER
283 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
284 "use the gnulib module sigprocmask for portability");
287 # if HAVE_RAW_DECL_SIGPENDING
288 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
289 "use the gnulib module sigprocmask for portability");
292 # if HAVE_RAW_DECL_SIGPROCMASK
293 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
294 "use the gnulib module sigprocmask for portability");
296 #endif /* @GNULIB_SIGPROCMASK@ */
299 #if @GNULIB_SIGACTION@
300 # if !@HAVE_SIGACTION@
302 # if !@HAVE_SIGINFO_T@
304 # if !GNULIB_defined_siginfo_types
306 /* Present to allow compilation, but unsupported by gnulib. */
313 /* Present to allow compilation, but unsupported by gnulib. */
324 union sigval si_value;
326 typedef struct siginfo_t siginfo_t;
328 # define GNULIB_defined_siginfo_types 1
331 # endif /* !@HAVE_SIGINFO_T@ */
333 /* We assume that platforms which lack the sigaction() function also lack
334 the 'struct sigaction' type, and vice versa. */
336 # if !GNULIB_defined_struct_sigaction
342 void (*_sa_handler) (int);
343 /* Present to allow compilation, but unsupported by gnulib. POSIX
344 says that implementations may, but not must, make sa_sigaction
345 overlap with sa_handler, but we know of no implementation where
346 they do not overlap. */
347 void (*_sa_sigaction) (int, siginfo_t *, void *);
350 /* Not all POSIX flags are supported. */
353 # define sa_handler _sa_func._sa_handler
354 # define sa_sigaction _sa_func._sa_sigaction
355 /* Unsupported flags are not present. */
356 # define SA_RESETHAND 1
357 # define SA_NODEFER 2
358 # define SA_RESTART 4
360 # define GNULIB_defined_struct_sigaction 1
363 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
364 struct sigaction *restrict));
366 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
368 # define sa_sigaction sa_handler
370 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
372 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
373 struct sigaction *restrict));
374 _GL_CXXALIASWARN (sigaction);
376 #elif defined GNULIB_POSIXCHECK
378 # if HAVE_RAW_DECL_SIGACTION
379 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
380 "use the gnulib module sigaction for portability");
384 /* Some systems don't have SA_NODEFER. */
386 # define SA_NODEFER 0
390 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
391 #endif /* _@GUARD_PREFIX@_SIGNAL_H */