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