Add gnulib support for pthread_sigmask.
[bpt/emacs.git] / lib / signal.in.h
1 /* A GNU-like <signal.h>.
2
3 Copyright (C) 2006-2011 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>. */
17
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
22
23 #if defined __need_sig_atomic_t || defined __need_sigset_t
24 /* Special invocation convention inside glibc header files. */
25
26 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
27
28 #else
29 /* Normal invocation convention. */
30
31 #ifndef _@GUARD_PREFIX@_SIGNAL_H
32
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>
38
39 /* The include_next requires a split double-inclusion guard. */
40 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
41
42 #ifndef _@GUARD_PREFIX@_SIGNAL_H
43 #define _@GUARD_PREFIX@_SIGNAL_H
44
45 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
46
47 /* The definition of _GL_ARG_NONNULL is copied here. */
48
49 /* The definition of _GL_WARN_ON_USE is copied here. */
50
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;
57 # undef sig_atomic_t
58 # define sig_atomic_t rpl_sig_atomic_t
59 # define GNULIB_defined_sig_atomic_t 1
60 # endif
61 #endif
62
63 /* A set or mask of signals. */
64 #if !@HAVE_SIGSET_T@
65 # if !GNULIB_defined_sigset_t
66 typedef unsigned int sigset_t;
67 # define GNULIB_defined_sigset_t 1
68 # endif
69 #endif
70
71 /* Define sighandler_t, the type of signal handlers. A GNU extension. */
72 #if !@HAVE_SIGHANDLER_T@
73 # ifdef __cplusplus
74 extern "C" {
75 # endif
76 # if !GNULIB_defined_sighandler_t
77 typedef void (*sighandler_t) (int);
78 # define GNULIB_defined_sighandler_t 1
79 # endif
80 # ifdef __cplusplus
81 }
82 # endif
83 #endif
84
85
86 #if @GNULIB_SIGNAL_H_SIGPIPE@
87 # ifndef SIGPIPE
88 /* Define SIGPIPE to a value that does not overlap with other signals. */
89 # define SIGPIPE 13
90 # define GNULIB_defined_SIGPIPE 1
91 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
92 'write', 'stdio'. */
93 # endif
94 #endif
95
96
97 /* Maximum signal number + 1. */
98 #ifndef NSIG
99 # if defined __TANDEM
100 # define NSIG 32
101 # endif
102 #endif
103
104
105 #if @GNULIB_PTHREAD_SIGMASK@
106 # if @REPLACE_PTHREAD_SIGMASK@
107 # undef pthread_sigmask
108 # define pthread_sigmask sigprocmask
109 # endif
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");
115 # endif
116 #endif
117
118
119 #if @GNULIB_SIGPROCMASK@
120 # if !@HAVE_POSIX_SIGNALBLOCKING@
121
122 /* Maximum signal number + 1. */
123 # ifndef NSIG
124 # define NSIG 32
125 # endif
126
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
131 # endif
132
133 # endif
134
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
139 # undef sigismember
140 # endif
141 # else
142 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
143 _GL_ARG_NONNULL ((1)));
144 # endif
145 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
146 _GL_CXXALIASWARN (sigismember);
147
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
152 # undef sigemptyset
153 # endif
154 # else
155 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
156 # endif
157 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
158 _GL_CXXALIASWARN (sigemptyset);
159
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
164 # undef sigaddset
165 # endif
166 # else
167 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
168 _GL_ARG_NONNULL ((1)));
169 # endif
170 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
171 _GL_CXXALIASWARN (sigaddset);
172
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
177 # undef sigdelset
178 # endif
179 # else
180 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
181 _GL_ARG_NONNULL ((1)));
182 # endif
183 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
184 _GL_CXXALIASWARN (sigdelset);
185
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
190 # undef sigfillset
191 # endif
192 # else
193 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
194 # endif
195 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
196 _GL_CXXALIASWARN (sigfillset);
197
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)));
201 # endif
202 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
203 _GL_CXXALIASWARN (sigpending);
204
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));
216 # endif
217 _GL_CXXALIAS_SYS (sigprocmask, int,
218 (int operation, const sigset_t *set, sigset_t *old_set));
219 _GL_CXXALIASWARN (sigprocmask);
220
221 /* Install the handler FUNC for signal SIG, and return the previous
222 handler. */
223 # ifdef __cplusplus
224 extern "C" {
225 # endif
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
229 # endif
230 # ifdef __cplusplus
231 }
232 # endif
233 # if !@HAVE_POSIX_SIGNALBLOCKING@
234 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
235 # define signal rpl_signal
236 # endif
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));
241 # else
242 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
243 (int sig, _gl_function_taking_int_returning_void_t func));
244 # endif
245 _GL_CXXALIASWARN (signal);
246
247 /* Raise signal SIG. */
248 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
249 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
250 # undef raise
251 # define raise rpl_raise
252 # endif
253 _GL_FUNCDECL_RPL (raise, int, (int sig));
254 _GL_CXXALIAS_RPL (raise, int, (int sig));
255 # else
256 _GL_CXXALIAS_SYS (raise, int, (int sig));
257 # endif
258 _GL_CXXALIASWARN (raise);
259
260 #elif defined GNULIB_POSIXCHECK
261 # undef sigaddset
262 # if HAVE_RAW_DECL_SIGADDSET
263 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
264 "use the gnulib module sigprocmask for portability");
265 # endif
266 # undef sigdelset
267 # if HAVE_RAW_DECL_SIGDELSET
268 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
269 "use the gnulib module sigprocmask for portability");
270 # endif
271 # undef sigemptyset
272 # if HAVE_RAW_DECL_SIGEMPTYSET
273 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
274 "use the gnulib module sigprocmask for portability");
275 # endif
276 # undef sigfillset
277 # if HAVE_RAW_DECL_SIGFILLSET
278 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
279 "use the gnulib module sigprocmask for portability");
280 # endif
281 # undef sigismember
282 # if HAVE_RAW_DECL_SIGISMEMBER
283 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
284 "use the gnulib module sigprocmask for portability");
285 # endif
286 # undef sigpending
287 # if HAVE_RAW_DECL_SIGPENDING
288 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
289 "use the gnulib module sigprocmask for portability");
290 # endif
291 # undef sigprocmask
292 # if HAVE_RAW_DECL_SIGPROCMASK
293 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
294 "use the gnulib module sigprocmask for portability");
295 # endif
296 #endif /* @GNULIB_SIGPROCMASK@ */
297
298
299 #if @GNULIB_SIGACTION@
300 # if !@HAVE_SIGACTION@
301
302 # if !@HAVE_SIGINFO_T@
303
304 # if !GNULIB_defined_siginfo_types
305
306 /* Present to allow compilation, but unsupported by gnulib. */
307 union sigval
308 {
309 int sival_int;
310 void *sival_ptr;
311 };
312
313 /* Present to allow compilation, but unsupported by gnulib. */
314 struct siginfo_t
315 {
316 int si_signo;
317 int si_code;
318 int si_errno;
319 pid_t si_pid;
320 uid_t si_uid;
321 void *si_addr;
322 int si_status;
323 long si_band;
324 union sigval si_value;
325 };
326 typedef struct siginfo_t siginfo_t;
327
328 # define GNULIB_defined_siginfo_types 1
329 # endif
330
331 # endif /* !@HAVE_SIGINFO_T@ */
332
333 /* We assume that platforms which lack the sigaction() function also lack
334 the 'struct sigaction' type, and vice versa. */
335
336 # if !GNULIB_defined_struct_sigaction
337
338 struct sigaction
339 {
340 union
341 {
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 *);
348 } _sa_func;
349 sigset_t sa_mask;
350 /* Not all POSIX flags are supported. */
351 int sa_flags;
352 };
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
359
360 # define GNULIB_defined_struct_sigaction 1
361 # endif
362
363 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
364 struct sigaction *restrict));
365
366 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
367
368 # define sa_sigaction sa_handler
369
370 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
371
372 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
373 struct sigaction *restrict));
374 _GL_CXXALIASWARN (sigaction);
375
376 #elif defined GNULIB_POSIXCHECK
377 # undef sigaction
378 # if HAVE_RAW_DECL_SIGACTION
379 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
380 "use the gnulib module sigaction for portability");
381 # endif
382 #endif
383
384 /* Some systems don't have SA_NODEFER. */
385 #ifndef SA_NODEFER
386 # define SA_NODEFER 0
387 #endif
388
389
390 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
391 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
392 #endif