1 /* A GNU-like <signal.h>.
3 Copyright (C) 2006-2009 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@
22 #if defined __need_sig_atomic_t || defined __need_sigset_t
23 /* Special invocation convention inside glibc header files. */
25 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
28 /* Normal invocation convention. */
32 /* The include_next requires a split double-inclusion guard. */
33 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
38 /* The definition of GL_LINK_WARNING is copied here. */
40 /* The definition of _GL_ARG_NONNULL is copied here. */
42 /* Define pid_t, uid_t.
43 Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */
44 #include <sys/types.h>
46 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
47 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
48 Hence, redefine this to a non-volatile type as needed. */
49 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
50 typedef int rpl_sig_atomic_t;
52 # define sig_atomic_t rpl_sig_atomic_t
55 /* A set or mask of signals. */
57 typedef unsigned int sigset_t;
65 #if @GNULIB_SIGNAL_H_SIGPIPE@
67 /* Define SIGPIPE to a value that does not overlap with other signals. */
69 # define GNULIB_defined_SIGPIPE 1
70 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
76 #if @GNULIB_SIGPROCMASK@
77 # if !@HAVE_POSIX_SIGNALBLOCKING@
79 /* Maximum signal number + 1. */
84 /* This code supports only 32 signals. */
85 typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
87 /* Test whether a given signal is contained in a signal set. */
88 extern int sigismember (const sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
90 /* Initialize a signal set to the empty set. */
91 extern int sigemptyset (sigset_t *set) _GL_ARG_NONNULL ((1));
93 /* Add a signal to a signal set. */
94 extern int sigaddset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
96 /* Remove a signal from a signal set. */
97 extern int sigdelset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
99 /* Fill a signal set with all possible signals. */
100 extern int sigfillset (sigset_t *set) _GL_ARG_NONNULL ((1));
102 /* Return the set of those blocked signals that are pending. */
103 extern int sigpending (sigset_t *set) _GL_ARG_NONNULL ((1));
105 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
106 Then, if SET is not NULL, affect the current set of blocked signals by
107 combining it with *SET as indicated in OPERATION.
108 In this implementation, you are not allowed to change a signal handler
109 while the signal is blocked. */
110 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
111 # define SIG_SETMASK 1 /* blocked_set = *set; */
112 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
113 extern int sigprocmask (int operation, const sigset_t *set, sigset_t *old_set);
115 # define signal rpl_signal
116 /* Install the handler FUNC for signal SIG, and return the previous
118 extern void (*signal (int sig, void (*func) (int))) (int);
120 # if GNULIB_defined_SIGPIPE
122 /* Raise signal SIG. */
124 # define raise rpl_raise
125 extern int raise (int sig);
129 # endif /* !@HAVE_POSIX_SIGNALBLOCKING@ */
130 #elif defined GNULIB_POSIXCHECK
132 # define sigaddset(s,n) \
133 (GL_LINK_WARNING ("sigaddset is unportable - " \
134 "use gnulib module sigprocmask for portability"), \
137 # define sigdelset(s,n) \
138 (GL_LINK_WARNING ("sigdelset is unportable - " \
139 "use gnulib module sigprocmask for portability"), \
142 # define sigemptyset(s) \
143 (GL_LINK_WARNING ("sigemptyset is unportable - " \
144 "use gnulib module sigprocmask for portability"), \
147 # define sigfillset(s) \
148 (GL_LINK_WARNING ("sigfillset is unportable - " \
149 "use gnulib module sigprocmask for portability"), \
152 # define sigismember(s,n) \
153 (GL_LINK_WARNING ("sigismember is unportable - " \
154 "use gnulib module sigprocmask for portability"), \
157 # define sigpending(s) \
158 (GL_LINK_WARNING ("sigpending is unportable - " \
159 "use gnulib module sigprocmask for portability"), \
162 # define sigprocmask(h,s,o) \
163 (GL_LINK_WARNING ("sigprocmask is unportable - " \
164 "use gnulib module sigprocmask for portability"), \
165 sigprocmask (h, s, o))
166 #endif /* @GNULIB_SIGPROCMASK@ */
169 #if @GNULIB_SIGACTION@
170 # if !@HAVE_SIGACTION@
172 # if !@HAVE_SIGINFO_T@
173 /* Present to allow compilation, but unsupported by gnulib. */
180 /* Present to allow compilation, but unsupported by gnulib. */
191 union sigval si_value;
193 typedef struct siginfo_t siginfo_t;
194 # endif /* !@HAVE_SIGINFO_T@ */
196 /* We assume that platforms which lack the sigaction() function also lack
197 the 'struct sigaction' type, and vice versa. */
203 void (*_sa_handler) (int);
204 /* Present to allow compilation, but unsupported by gnulib. POSIX
205 says that implementations may, but not must, make sa_sigaction
206 overlap with sa_handler, but we know of no implementation where
207 they do not overlap. */
208 void (*_sa_sigaction) (int, siginfo_t *, void *);
211 /* Not all POSIX flags are supported. */
214 # define sa_handler _sa_func._sa_handler
215 # define sa_sigaction _sa_func._sa_sigaction
216 /* Unsupported flags are not present. */
217 # define SA_RESETHAND 1
218 # define SA_NODEFER 2
219 # define SA_RESTART 4
221 extern int sigaction (int, const struct sigaction *restrict,
222 struct sigaction *restrict);
224 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
226 # define sa_sigaction sa_handler
228 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
229 #elif defined GNULIB_POSIXCHECK
231 # define sigaction(s,a,o) \
232 (GL_LINK_WARNING ("sigaction is unportable - " \
233 "use gnulib module sigaction for portability"), \
237 /* Some systems don't have SA_NODEFER. */
239 # define SA_NODEFER 0
247 #endif /* _GL_SIGNAL_H */
248 #endif /* _GL_SIGNAL_H */