Merge branch 'upstream' into stable
[gnulib.git] / lib / signal.in.h
1 /* A GNU-like <signal.h>.
2
3    Copyright (C) 2006-2009 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 definition of GL_LINK_WARNING is copied here.  */
39
40 /* The definition of _GL_ARG_NONNULL is copied here.  */
41
42 /* Define pid_t, uid_t.
43    Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.  */
44 #include <sys/types.h>
45
46 /* On AIX, sig_atomic_t already includes volatile.  C99 requires that
47    'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
48    Hence, redefine this to a non-volatile type as needed.  */
49 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
50 typedef int rpl_sig_atomic_t;
51 # undef sig_atomic_t
52 # define sig_atomic_t rpl_sig_atomic_t
53 #endif
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59
60 #if @GNULIB_SIGNAL_H_SIGPIPE@
61 # ifndef SIGPIPE
62 /* Define SIGPIPE to a value that does not overlap with other signals.  */
63 #  define SIGPIPE 13
64 #  define GNULIB_defined_SIGPIPE 1
65 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
66    'write', 'stdio'.  */
67 # endif
68 #endif
69
70
71 #if !@HAVE_POSIX_SIGNALBLOCKING@
72
73 /* Maximum signal number + 1.  */
74 # ifndef NSIG
75 #  define NSIG 32
76 # endif
77
78 /* This code supports only 32 signals.  */
79 typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
80
81 /* A set or mask of signals.  */
82 # if !@HAVE_SIGSET_T@
83 typedef unsigned int sigset_t;
84 # endif
85
86 /* Test whether a given signal is contained in a signal set.  */
87 extern int sigismember (const sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
88
89 /* Initialize a signal set to the empty set.  */
90 extern int sigemptyset (sigset_t *set) _GL_ARG_NONNULL ((1));
91
92 /* Add a signal to a signal set.  */
93 extern int sigaddset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
94
95 /* Remove a signal from a signal set.  */
96 extern int sigdelset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
97
98 /* Fill a signal set with all possible signals.  */
99 extern int sigfillset (sigset_t *set) _GL_ARG_NONNULL ((1));
100
101 /* Return the set of those blocked signals that are pending.  */
102 extern int sigpending (sigset_t *set) _GL_ARG_NONNULL ((1));
103
104 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
105    Then, if SET is not NULL, affect the current set of blocked signals by
106    combining it with *SET as indicated in OPERATION.
107    In this implementation, you are not allowed to change a signal handler
108    while the signal is blocked.  */
109 # define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
110 # define SIG_SETMASK 1  /* blocked_set = *set; */
111 # define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
112 extern int sigprocmask (int operation, const sigset_t *set, sigset_t *old_set);
113
114 # define signal rpl_signal
115 /* Install the handler FUNC for signal SIG, and return the previous
116    handler.  */
117 extern void (*signal (int sig, void (*func) (int))) (int);
118
119 # if GNULIB_defined_SIGPIPE
120
121 /* Raise signal SIG.  */
122 #  undef raise
123 #  define raise rpl_raise
124 extern int raise (int sig);
125
126 # endif
127
128 #endif /* !@HAVE_POSIX_SIGNALBLOCKING@ */
129
130
131 #if !@HAVE_SIGACTION@
132
133 # if !@HAVE_SIGINFO_T@
134 /* Present to allow compilation, but unsupported by gnulib.  */
135 union sigval
136 {
137   int sival_int;
138   void *sival_ptr;
139 };
140
141 /* Present to allow compilation, but unsupported by gnulib.  */
142 struct siginfo_t
143 {
144   int si_signo;
145   int si_code;
146   int si_errno;
147   pid_t si_pid;
148   uid_t si_uid;
149   void *si_addr;
150   int si_status;
151   long si_band;
152   union sigval si_value;
153 };
154 typedef struct siginfo_t siginfo_t;
155 # endif /* !@HAVE_SIGINFO_T@ */
156
157 /* We assume that platforms which lack the sigaction() function also lack
158    the 'struct sigaction' type, and vice versa.  */
159
160 struct sigaction
161 {
162   union
163   {
164     void (*_sa_handler) (int);
165     /* Present to allow compilation, but unsupported by gnulib.  POSIX
166        says that implementations may, but not must, make sa_sigaction
167        overlap with sa_handler, but we know of no implementation where
168        they do not overlap.  */
169     void (*_sa_sigaction) (int, siginfo_t *, void *);
170   } _sa_func;
171   sigset_t sa_mask;
172   /* Not all POSIX flags are supported.  */
173   int sa_flags;
174 };
175 # define sa_handler _sa_func._sa_handler
176 # define sa_sigaction _sa_func._sa_sigaction
177 /* Unsupported flags are not present.  */
178 # define SA_RESETHAND 1
179 # define SA_NODEFER 2
180 # define SA_RESTART 4
181
182 extern int sigaction (int, const struct sigaction *restrict,
183                       struct sigaction *restrict);
184
185 #elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
186
187 # define sa_sigaction sa_handler
188
189 #endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
190
191
192 /* Some systems don't have SA_NODEFER.  */
193 #ifndef SA_NODEFER
194 # define SA_NODEFER 0
195 #endif
196
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif /* _GL_SIGNAL_H */
203 #endif /* _GL_SIGNAL_H */
204 #endif