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