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