maint: update almost all copyright ranges to include 2011
[gnulib.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 _GL_SIGNAL_H
32
33 /* The include_next requires a split double-inclusion guard.  */
34 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
35
36 #ifndef _GL_SIGNAL_H
37 #define _GL_SIGNAL_H
38
39 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
40
41 /* The definition of _GL_ARG_NONNULL is copied here.  */
42
43 /* The definition of _GL_WARN_ON_USE is copied here.  */
44
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>
48
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 typedef int rpl_sig_atomic_t;
54 # undef sig_atomic_t
55 # define sig_atomic_t rpl_sig_atomic_t
56 #endif
57
58 /* A set or mask of signals.  */
59 #if !@HAVE_SIGSET_T@
60 typedef unsigned int sigset_t;
61 #endif
62
63
64 #if @GNULIB_SIGNAL_H_SIGPIPE@
65 # ifndef SIGPIPE
66 /* Define SIGPIPE to a value that does not overlap with other signals.  */
67 #  define SIGPIPE 13
68 #  define GNULIB_defined_SIGPIPE 1
69 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
70    'write', 'stdio'.  */
71 # endif
72 #endif
73
74
75 /* Maximum signal number + 1.  */
76 #ifndef NSIG
77 # if defined __TANDEM
78 #  define NSIG 32
79 # endif
80 #endif
81
82
83 #if @GNULIB_SIGPROCMASK@
84 # if !@HAVE_POSIX_SIGNALBLOCKING@
85
86 /* Maximum signal number + 1.  */
87 #  ifndef NSIG
88 #   define NSIG 32
89 #  endif
90
91 /* This code supports only 32 signals.  */
92 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
93
94 # endif
95
96 /* Test whether a given signal is contained in a signal set.  */
97 # if @HAVE_POSIX_SIGNALBLOCKING@
98 /* This function is defined as a macro on MacOS X.  */
99 #  if defined __cplusplus && defined GNULIB_NAMESPACE
100 #   undef sigismember
101 #  endif
102 # else
103 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
104                                     _GL_ARG_NONNULL ((1)));
105 # endif
106 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
107 _GL_CXXALIASWARN (sigismember);
108
109 /* Initialize a signal set to the empty set.  */
110 # if @HAVE_POSIX_SIGNALBLOCKING@
111 /* This function is defined as a macro on MacOS X.  */
112 #  if defined __cplusplus && defined GNULIB_NAMESPACE
113 #   undef sigemptyset
114 #  endif
115 # else
116 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
117 # endif
118 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
119 _GL_CXXALIASWARN (sigemptyset);
120
121 /* Add a signal to a signal set.  */
122 # if @HAVE_POSIX_SIGNALBLOCKING@
123 /* This function is defined as a macro on MacOS X.  */
124 #  if defined __cplusplus && defined GNULIB_NAMESPACE
125 #   undef sigaddset
126 #  endif
127 # else
128 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
129                                   _GL_ARG_NONNULL ((1)));
130 # endif
131 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
132 _GL_CXXALIASWARN (sigaddset);
133
134 /* Remove a signal from a signal set.  */
135 # if @HAVE_POSIX_SIGNALBLOCKING@
136 /* This function is defined as a macro on MacOS X.  */
137 #  if defined __cplusplus && defined GNULIB_NAMESPACE
138 #   undef sigdelset
139 #  endif
140 # else
141 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
142                                   _GL_ARG_NONNULL ((1)));
143 # endif
144 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
145 _GL_CXXALIASWARN (sigdelset);
146
147 /* Fill a signal set with all possible signals.  */
148 # if @HAVE_POSIX_SIGNALBLOCKING@
149 /* This function is defined as a macro on MacOS X.  */
150 #  if defined __cplusplus && defined GNULIB_NAMESPACE
151 #   undef sigfillset
152 #  endif
153 # else
154 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
155 # endif
156 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
157 _GL_CXXALIASWARN (sigfillset);
158
159 /* Return the set of those blocked signals that are pending.  */
160 # if !@HAVE_POSIX_SIGNALBLOCKING@
161 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
162 # endif
163 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
164 _GL_CXXALIASWARN (sigpending);
165
166 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
167    Then, if SET is not NULL, affect the current set of blocked signals by
168    combining it with *SET as indicated in OPERATION.
169    In this implementation, you are not allowed to change a signal handler
170    while the signal is blocked.  */
171 # if !@HAVE_POSIX_SIGNALBLOCKING@
172 #  define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
173 #  define SIG_SETMASK 1  /* blocked_set = *set; */
174 #  define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
175 _GL_FUNCDECL_SYS (sigprocmask, int,
176                   (int operation, const sigset_t *set, sigset_t *old_set));
177 # endif
178 _GL_CXXALIAS_SYS (sigprocmask, int,
179                   (int operation, const sigset_t *set, sigset_t *old_set));
180 _GL_CXXALIASWARN (sigprocmask);
181
182 /* Install the handler FUNC for signal SIG, and return the previous
183    handler.  */
184 # ifdef __cplusplus
185 extern "C" {
186 # endif
187 typedef void (*_gl_function_taking_int_returning_void_t) (int);
188 # ifdef __cplusplus
189 }
190 # endif
191 # if !@HAVE_POSIX_SIGNALBLOCKING@
192 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
193 #   define signal rpl_signal
194 #  endif
195 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
196                   (int sig, _gl_function_taking_int_returning_void_t func));
197 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
198                   (int sig, _gl_function_taking_int_returning_void_t func));
199 # else
200 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
201                   (int sig, _gl_function_taking_int_returning_void_t func));
202 # endif
203 _GL_CXXALIASWARN (signal);
204
205 /* Raise signal SIG.  */
206 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
207 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
208 #   undef raise
209 #   define raise rpl_raise
210 #  endif
211 _GL_FUNCDECL_RPL (raise, int, (int sig));
212 _GL_CXXALIAS_RPL (raise, int, (int sig));
213 # else
214 _GL_CXXALIAS_SYS (raise, int, (int sig));
215 # endif
216 _GL_CXXALIASWARN (raise);
217
218 #elif defined GNULIB_POSIXCHECK
219 # undef sigaddset
220 # if HAVE_RAW_DECL_SIGADDSET
221 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
222                  "use the gnulib module sigprocmask for portability");
223 # endif
224 # undef sigdelset
225 # if HAVE_RAW_DECL_SIGDELSET
226 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
227                  "use the gnulib module sigprocmask for portability");
228 # endif
229 # undef sigemptyset
230 # if HAVE_RAW_DECL_SIGEMPTYSET
231 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
232                  "use the gnulib module sigprocmask for portability");
233 # endif
234 # undef sigfillset
235 # if HAVE_RAW_DECL_SIGFILLSET
236 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
237                  "use the gnulib module sigprocmask for portability");
238 # endif
239 # undef sigismember
240 # if HAVE_RAW_DECL_SIGISMEMBER
241 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
242                  "use the gnulib module sigprocmask for portability");
243 # endif
244 # undef sigpending
245 # if HAVE_RAW_DECL_SIGPENDING
246 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
247                  "use the gnulib module sigprocmask for portability");
248 # endif
249 # undef sigprocmask
250 # if HAVE_RAW_DECL_SIGPROCMASK
251 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
252                  "use the gnulib module sigprocmask for portability");
253 # endif
254 #endif /* @GNULIB_SIGPROCMASK@ */
255
256
257 #if @GNULIB_SIGACTION@
258 # if !@HAVE_SIGACTION@
259
260 #  if !@HAVE_SIGINFO_T@
261 /* Present to allow compilation, but unsupported by gnulib.  */
262 union sigval
263 {
264   int sival_int;
265   void *sival_ptr;
266 };
267
268 /* Present to allow compilation, but unsupported by gnulib.  */
269 struct siginfo_t
270 {
271   int si_signo;
272   int si_code;
273   int si_errno;
274   pid_t si_pid;
275   uid_t si_uid;
276   void *si_addr;
277   int si_status;
278   long si_band;
279   union sigval si_value;
280 };
281 typedef struct siginfo_t siginfo_t;
282 #  endif /* !@HAVE_SIGINFO_T@ */
283
284 /* We assume that platforms which lack the sigaction() function also lack
285    the 'struct sigaction' type, and vice versa.  */
286
287 struct sigaction
288 {
289   union
290   {
291     void (*_sa_handler) (int);
292     /* Present to allow compilation, but unsupported by gnulib.  POSIX
293        says that implementations may, but not must, make sa_sigaction
294        overlap with sa_handler, but we know of no implementation where
295        they do not overlap.  */
296     void (*_sa_sigaction) (int, siginfo_t *, void *);
297   } _sa_func;
298   sigset_t sa_mask;
299   /* Not all POSIX flags are supported.  */
300   int sa_flags;
301 };
302 #  define sa_handler _sa_func._sa_handler
303 #  define sa_sigaction _sa_func._sa_sigaction
304 /* Unsupported flags are not present.  */
305 #  define SA_RESETHAND 1
306 #  define SA_NODEFER 2
307 #  define SA_RESTART 4
308
309 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
310                                    struct sigaction *restrict));
311
312 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
313
314 #  define sa_sigaction sa_handler
315
316 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
317
318 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
319                                    struct sigaction *restrict));
320 _GL_CXXALIASWARN (sigaction);
321
322 #elif defined GNULIB_POSIXCHECK
323 # undef sigaction
324 # if HAVE_RAW_DECL_SIGACTION
325 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
326                  "use the gnulib module sigaction for portability");
327 # endif
328 #endif
329
330 /* Some systems don't have SA_NODEFER.  */
331 #ifndef SA_NODEFER
332 # define SA_NODEFER 0
333 #endif
334
335
336 #endif /* _GL_SIGNAL_H */
337 #endif /* _GL_SIGNAL_H */
338 #endif