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