signal, spawn: use link warnings
[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 /* A set or mask of signals.  */
56 #if !@HAVE_SIGSET_T@
57 typedef unsigned int sigset_t;
58 #endif
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64
65 #if @GNULIB_SIGNAL_H_SIGPIPE@
66 # ifndef SIGPIPE
67 /* Define SIGPIPE to a value that does not overlap with other signals.  */
68 #  define SIGPIPE 13
69 #  define GNULIB_defined_SIGPIPE 1
70 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
71    'write', 'stdio'.  */
72 # endif
73 #endif
74
75
76 #if @GNULIB_SIGPROCMASK@
77 # if !@HAVE_POSIX_SIGNALBLOCKING@
78
79 /* Maximum signal number + 1.  */
80 #  ifndef NSIG
81 #   define NSIG 32
82 #  endif
83
84 /* This code supports only 32 signals.  */
85 typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
86
87 /* Test whether a given signal is contained in a signal set.  */
88 extern int sigismember (const sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
89
90 /* Initialize a signal set to the empty set.  */
91 extern int sigemptyset (sigset_t *set) _GL_ARG_NONNULL ((1));
92
93 /* Add a signal to a signal set.  */
94 extern int sigaddset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
95
96 /* Remove a signal from a signal set.  */
97 extern int sigdelset (sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
98
99 /* Fill a signal set with all possible signals.  */
100 extern int sigfillset (sigset_t *set) _GL_ARG_NONNULL ((1));
101
102 /* Return the set of those blocked signals that are pending.  */
103 extern int sigpending (sigset_t *set) _GL_ARG_NONNULL ((1));
104
105 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
106    Then, if SET is not NULL, affect the current set of blocked signals by
107    combining it with *SET as indicated in OPERATION.
108    In this implementation, you are not allowed to change a signal handler
109    while the signal is blocked.  */
110 #  define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
111 #  define SIG_SETMASK 1  /* blocked_set = *set; */
112 #  define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
113 extern int sigprocmask (int operation, const sigset_t *set, sigset_t *old_set);
114
115 #  define signal rpl_signal
116 /* Install the handler FUNC for signal SIG, and return the previous
117    handler.  */
118 extern void (*signal (int sig, void (*func) (int))) (int);
119
120 #  if GNULIB_defined_SIGPIPE
121
122 /* Raise signal SIG.  */
123 #   undef raise
124 #   define raise rpl_raise
125 extern int raise (int sig);
126
127 #  endif
128
129 # endif /* !@HAVE_POSIX_SIGNALBLOCKING@ */
130 #elif defined GNULIB_POSIXCHECK
131 # undef sigaddset
132 # define sigaddset(s,n) \
133   (GL_LINK_WARNING ("sigaddset is unportable - "        \
134                     "use gnulib module sigprocmask for portability"),   \
135    sigaddset (s, n))
136 # undef sigdelset
137 # define sigdelset(s,n) \
138   (GL_LINK_WARNING ("sigdelset is unportable - "        \
139                     "use gnulib module sigprocmask for portability"),   \
140    sigdelset (s, n))
141 # undef sigemptyset
142 # define sigemptyset(s) \
143   (GL_LINK_WARNING ("sigemptyset is unportable - "        \
144                     "use gnulib module sigprocmask for portability"),   \
145    sigemptyset (s))
146 # undef sigfillset
147 # define sigfillset(s) \
148   (GL_LINK_WARNING ("sigfillset is unportable - "        \
149                     "use gnulib module sigprocmask for portability"),   \
150    sigfillset (s))
151 # undef sigismember
152 # define sigismember(s,n) \
153   (GL_LINK_WARNING ("sigismember is unportable - "        \
154                     "use gnulib module sigprocmask for portability"),   \
155    sigismember (s, n))
156 # undef sigpending
157 # define sigpending(s) \
158   (GL_LINK_WARNING ("sigpending is unportable - "        \
159                     "use gnulib module sigprocmask for portability"),   \
160    sigpending (s))
161 # undef sigprocmask
162 # define sigprocmask(h,s,o)                               \
163   (GL_LINK_WARNING ("sigprocmask is unportable - "        \
164                     "use gnulib module sigprocmask for portability"),   \
165    sigprocmask (h, s, o))
166 #endif /* @GNULIB_SIGPROCMASK@ */
167
168
169 #if @GNULIB_SIGACTION@
170 # if !@HAVE_SIGACTION@
171
172 #  if !@HAVE_SIGINFO_T@
173 /* Present to allow compilation, but unsupported by gnulib.  */
174 union sigval
175 {
176   int sival_int;
177   void *sival_ptr;
178 };
179
180 /* Present to allow compilation, but unsupported by gnulib.  */
181 struct siginfo_t
182 {
183   int si_signo;
184   int si_code;
185   int si_errno;
186   pid_t si_pid;
187   uid_t si_uid;
188   void *si_addr;
189   int si_status;
190   long si_band;
191   union sigval si_value;
192 };
193 typedef struct siginfo_t siginfo_t;
194 #  endif /* !@HAVE_SIGINFO_T@ */
195
196 /* We assume that platforms which lack the sigaction() function also lack
197    the 'struct sigaction' type, and vice versa.  */
198
199 struct sigaction
200 {
201   union
202   {
203     void (*_sa_handler) (int);
204     /* Present to allow compilation, but unsupported by gnulib.  POSIX
205        says that implementations may, but not must, make sa_sigaction
206        overlap with sa_handler, but we know of no implementation where
207        they do not overlap.  */
208     void (*_sa_sigaction) (int, siginfo_t *, void *);
209   } _sa_func;
210   sigset_t sa_mask;
211   /* Not all POSIX flags are supported.  */
212   int sa_flags;
213 };
214 #  define sa_handler _sa_func._sa_handler
215 #  define sa_sigaction _sa_func._sa_sigaction
216 /* Unsupported flags are not present.  */
217 #  define SA_RESETHAND 1
218 #  define SA_NODEFER 2
219 #  define SA_RESTART 4
220
221 extern int sigaction (int, const struct sigaction *restrict,
222                       struct sigaction *restrict);
223
224 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
225
226 #  define sa_sigaction sa_handler
227
228 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
229 #elif defined GNULIB_POSIXCHECK
230 # undef sigaction
231 # define sigaction(s,a,o)                               \
232   (GL_LINK_WARNING ("sigaction is unportable - "        \
233                     "use gnulib module sigaction for portability"),   \
234    sigaction (s, a, o))
235 #endif
236
237 /* Some systems don't have SA_NODEFER.  */
238 #ifndef SA_NODEFER
239 # define SA_NODEFER 0
240 #endif
241
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247 #endif /* _GL_SIGNAL_H */
248 #endif /* _GL_SIGNAL_H */
249 #endif