Avoid some "gcc -pedantic" warnings.
[gnulib.git] / lib / signal.in.h
1 /* A GNU-like <signal.h>.
2
3    Copyright (C) 2006-2008 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 @PRAGMA_SYSTEM_HEADER@
19
20 #if defined __need_sig_atomic_t || defined __need_sigset_t
21 /* Special invocation convention inside glibc header files.  */
22
23 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
24
25 #else
26 /* Normal invocation convention.  */
27
28 #ifndef _GL_SIGNAL_H
29
30 /* The include_next requires a split double-inclusion guard.  */
31 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
32
33 #ifndef _GL_SIGNAL_H
34 #define _GL_SIGNAL_H
35
36 /* The definition of GL_LINK_WARNING is copied here.  */
37
38 /* Define pid_t, uid_t.
39    Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.  */
40 #include <sys/types.h>
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47 #if !@HAVE_POSIX_SIGNALBLOCKING@
48
49 /* Maximum signal number + 1.  */
50 # ifndef NSIG
51 #  define NSIG 32
52 # endif
53
54 /* This code supports only 32 signals.  */
55 typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
56
57 /* A set or mask of signals.  */
58 # if !@HAVE_SIGSET_T@
59 typedef unsigned int sigset_t;
60 # endif
61
62 /* Test whether a given signal is contained in a signal set.  */
63 extern int sigismember (const sigset_t *set, int sig);
64
65 /* Initialize a signal set to the empty set.  */
66 extern int sigemptyset (sigset_t *set);
67
68 /* Add a signal to a signal set.  */
69 extern int sigaddset (sigset_t *set, int sig);
70
71 /* Remove a signal from a signal set.  */
72 extern int sigdelset (sigset_t *set, int sig);
73
74 /* Fill a signal set with all possible signals.  */
75 extern int sigfillset (sigset_t *set);
76
77 /* Return the set of those blocked signals that are pending.  */
78 extern int sigpending (sigset_t *set);
79
80 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
81    Then, if SET is not NULL, affect the current set of blocked signals by
82    combining it with *SET as indicated in OPERATION.
83    In this implementation, you are not allowed to change a signal handler
84    while the signal is blocked.  */
85 # define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
86 # define SIG_SETMASK 1  /* blocked_set = *set; */
87 # define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
88 extern int sigprocmask (int operation, const sigset_t *set, sigset_t *old_set);
89
90 # define signal rpl_signal
91 /* Install the handler FUNC for signal SIG, and return the previous
92    handler.  */
93 extern void (*signal (int sig, void (*func) (int))) (int);
94
95 #endif /* !@HAVE_POSIX_SIGNALBLOCKING@ */
96
97 #if !@HAVE_SIGACTION@
98
99 # if !@HAVE_SIGINFO_T@
100 /* Present to allow compilation, but unsupported by gnulib.  */
101 union sigval
102 {
103   int sival_int;
104   void *sival_ptr;
105 };
106
107 /* Present to allow compilation, but unsupported by gnulib.  */
108 struct siginfo_t
109 {
110   int si_signo;
111   int si_code;
112   int si_errno;
113   pid_t si_pid;
114   uid_t si_uid;
115   void *si_addr;
116   int si_status;
117   long si_band;
118   union sigval si_value;
119 };
120 typedef struct siginfo_t siginfo_t;
121 # endif /* !@HAVE_SIGINFO_T@ */
122
123 /* We assume that platforms which lack the sigaction() function also lack
124    the 'struct sigaction' type, and vice versa.  */
125
126 struct sigaction
127 {
128   union
129   {
130     void (*_sa_handler) (int);
131     /* Present to allow compilation, but unsupported by gnulib.  POSIX
132        says that implementations may, but not must, make sa_sigaction
133        overlap with sa_handler, but we know of no implementation where
134        they do not overlap.  */
135     void (*_sa_sigaction) (int, siginfo_t *, void *);
136   } _sa_func;
137   sigset_t sa_mask;
138   /* Not all POSIX flags are supported.  */
139   int sa_flags;
140 };
141 # define sa_handler _sa_func._sa_handler
142 # define sa_sigaction _sa_func._sa_sigaction
143 /* Unsupported flags are not present.  */
144 # define SA_RESETHAND 1
145 # define SA_NODEFER 2
146 # define SA_RESTART 4
147
148 extern int sigaction (int, const struct sigaction *restrict,
149                       struct sigaction *restrict);
150
151 #elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
152
153 # define sa_sigaction sa_handler
154
155 #endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
156
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif /* _GL_SIGNAL_H */
163 #endif /* _GL_SIGNAL_H */
164 #endif