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. */
33 /* The include_next requires a split double-inclusion guard. */
34 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
39 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
41 /* The definition of _GL_ARG_NONNULL is copied here. */
43 /* The definition of _GL_WARN_ON_USE is copied here. */
45 /* Define pid_t, uid_t.
46 Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */
47 #include <sys/types.h>
49 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
50 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
51 Hence, redefine this to a non-volatile type as needed. */
52 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
53 # if !GNULIB_defined_sig_atomic_t
54 typedef int rpl_sig_atomic_t;
56 # define sig_atomic_t rpl_sig_atomic_t
57 # define GNULIB_defined_sig_atomic_t 1
61 /* A set or mask of signals. */
63 # if !GNULIB_defined_sigset_t
64 typedef unsigned int sigset_t;
65 # define GNULIB_defined_sigset_t 1
70 #if @GNULIB_SIGNAL_H_SIGPIPE@
72 /* Define SIGPIPE to a value that does not overlap with other signals. */
74 # define GNULIB_defined_SIGPIPE 1
75 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
81 /* Maximum signal number + 1. */
89 #if @GNULIB_SIGPROCMASK@
90 # if !@HAVE_POSIX_SIGNALBLOCKING@
92 /* Maximum signal number + 1. */
97 /* This code supports only 32 signals. */
98 # if !GNULIB_defined_verify_NSIG_constraint
99 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
100 # define GNULIB_defined_verify_NSIG_constraint 1
105 /* Test whether a given signal is contained in a signal set. */
106 # if @HAVE_POSIX_SIGNALBLOCKING@
107 /* This function is defined as a macro on MacOS X. */
108 # if defined __cplusplus && defined GNULIB_NAMESPACE
112 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
113 _GL_ARG_NONNULL ((1)));
115 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
116 _GL_CXXALIASWARN (sigismember);
118 /* Initialize a signal set to the empty set. */
119 # if @HAVE_POSIX_SIGNALBLOCKING@
120 /* This function is defined as a macro on MacOS X. */
121 # if defined __cplusplus && defined GNULIB_NAMESPACE
125 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
127 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
128 _GL_CXXALIASWARN (sigemptyset);
130 /* Add a signal to a signal set. */
131 # if @HAVE_POSIX_SIGNALBLOCKING@
132 /* This function is defined as a macro on MacOS X. */
133 # if defined __cplusplus && defined GNULIB_NAMESPACE
137 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
138 _GL_ARG_NONNULL ((1)));
140 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
141 _GL_CXXALIASWARN (sigaddset);
143 /* Remove a signal from a signal set. */
144 # if @HAVE_POSIX_SIGNALBLOCKING@
145 /* This function is defined as a macro on MacOS X. */
146 # if defined __cplusplus && defined GNULIB_NAMESPACE
150 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
151 _GL_ARG_NONNULL ((1)));
153 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
154 _GL_CXXALIASWARN (sigdelset);
156 /* Fill a signal set with all possible signals. */
157 # if @HAVE_POSIX_SIGNALBLOCKING@
158 /* This function is defined as a macro on MacOS X. */
159 # if defined __cplusplus && defined GNULIB_NAMESPACE
163 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
165 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
166 _GL_CXXALIASWARN (sigfillset);
168 /* Return the set of those blocked signals that are pending. */
169 # if !@HAVE_POSIX_SIGNALBLOCKING@
170 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
172 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
173 _GL_CXXALIASWARN (sigpending);
175 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
176 Then, if SET is not NULL, affect the current set of blocked signals by
177 combining it with *SET as indicated in OPERATION.
178 In this implementation, you are not allowed to change a signal handler
179 while the signal is blocked. */
180 # if !@HAVE_POSIX_SIGNALBLOCKING@
181 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
182 # define SIG_SETMASK 1 /* blocked_set = *set; */
183 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
184 _GL_FUNCDECL_SYS (sigprocmask, int,
185 (int operation, const sigset_t *set, sigset_t *old_set));
187 _GL_CXXALIAS_SYS (sigprocmask, int,
188 (int operation, const sigset_t *set, sigset_t *old_set));
189 _GL_CXXALIASWARN (sigprocmask);
191 /* Install the handler FUNC for signal SIG, and return the previous
196 # if !GNULIB_defined_function_taking_int_returning_void_t
197 typedef void (*_gl_function_taking_int_returning_void_t) (int);
198 # define GNULIB_defined_function_taking_int_returning_void_t 1
203 # if !@HAVE_POSIX_SIGNALBLOCKING@
204 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
205 # define signal rpl_signal
207 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
208 (int sig, _gl_function_taking_int_returning_void_t func));
209 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
210 (int sig, _gl_function_taking_int_returning_void_t func));
212 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
213 (int sig, _gl_function_taking_int_returning_void_t func));
215 _GL_CXXALIASWARN (signal);
217 /* Raise signal SIG. */
218 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
219 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
221 # define raise rpl_raise
223 _GL_FUNCDECL_RPL (raise, int, (int sig));
224 _GL_CXXALIAS_RPL (raise, int, (int sig));
226 _GL_CXXALIAS_SYS (raise, int, (int sig));
228 _GL_CXXALIASWARN (raise);
230 #elif defined GNULIB_POSIXCHECK
232 # if HAVE_RAW_DECL_SIGADDSET
233 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
234 "use the gnulib module sigprocmask for portability");
237 # if HAVE_RAW_DECL_SIGDELSET
238 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
239 "use the gnulib module sigprocmask for portability");
242 # if HAVE_RAW_DECL_SIGEMPTYSET
243 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
244 "use the gnulib module sigprocmask for portability");
247 # if HAVE_RAW_DECL_SIGFILLSET
248 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
249 "use the gnulib module sigprocmask for portability");
252 # if HAVE_RAW_DECL_SIGISMEMBER
253 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
254 "use the gnulib module sigprocmask for portability");
257 # if HAVE_RAW_DECL_SIGPENDING
258 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
259 "use the gnulib module sigprocmask for portability");
262 # if HAVE_RAW_DECL_SIGPROCMASK
263 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
264 "use the gnulib module sigprocmask for portability");
266 #endif /* @GNULIB_SIGPROCMASK@ */
269 #if @GNULIB_SIGACTION@
270 # if !@HAVE_SIGACTION@
272 # if !@HAVE_SIGINFO_T@
274 # if !GNULIB_defined_siginfo_types
276 /* Present to allow compilation, but unsupported by gnulib. */
283 /* Present to allow compilation, but unsupported by gnulib. */
294 union sigval si_value;
296 typedef struct siginfo_t siginfo_t;
298 # define GNULIB_defined_siginfo_types 1
301 # endif /* !@HAVE_SIGINFO_T@ */
303 /* We assume that platforms which lack the sigaction() function also lack
304 the 'struct sigaction' type, and vice versa. */
306 # if !GNULIB_defined_struct_sigaction
312 void (*_sa_handler) (int);
313 /* Present to allow compilation, but unsupported by gnulib. POSIX
314 says that implementations may, but not must, make sa_sigaction
315 overlap with sa_handler, but we know of no implementation where
316 they do not overlap. */
317 void (*_sa_sigaction) (int, siginfo_t *, void *);
320 /* Not all POSIX flags are supported. */
323 # define sa_handler _sa_func._sa_handler
324 # define sa_sigaction _sa_func._sa_sigaction
325 /* Unsupported flags are not present. */
326 # define SA_RESETHAND 1
327 # define SA_NODEFER 2
328 # define SA_RESTART 4
330 # define GNULIB_defined_struct_sigaction 1
333 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
334 struct sigaction *restrict));
336 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
338 # define sa_sigaction sa_handler
340 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
342 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
343 struct sigaction *restrict));
344 _GL_CXXALIASWARN (sigaction);
346 #elif defined GNULIB_POSIXCHECK
348 # if HAVE_RAW_DECL_SIGACTION
349 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
350 "use the gnulib module sigaction for portability");
354 /* Some systems don't have SA_NODEFER. */
356 # define SA_NODEFER 0
360 #endif /* _GL_SIGNAL_H */
361 #endif /* _GL_SIGNAL_H */