1 |
2 |
drasko |
/* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
|
2 |
|
|
Copyright (C) 1991, 1992, 1994, 1996, 1997 Free Software Foundation, Inc.
|
3 |
|
|
This file is part of the GNU C Library.
|
4 |
|
|
|
5 |
|
|
The GNU C Library is free software; you can redistribute it and/or
|
6 |
|
|
modify it under the terms of the GNU Lesser General Public
|
7 |
|
|
License as published by the Free Software Foundation; either
|
8 |
|
|
version 2.1 of the License, or (at your option) any later version.
|
9 |
|
|
|
10 |
|
|
The GNU C Library 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 GNU
|
13 |
|
|
Lesser General Public License for more details.
|
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU Lesser General Public
|
16 |
|
|
License along with the GNU C Library; if not, write to the Free
|
17 |
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
18 |
|
|
02111-1307 USA. */
|
19 |
|
|
|
20 |
|
|
#ifndef _SIGSET_H_types
|
21 |
|
|
# define _SIGSET_H_types 1
|
22 |
|
|
|
23 |
|
|
typedef int __sig_atomic_t;
|
24 |
|
|
|
25 |
|
|
/* A `sigset_t' has a bit for each signal. */
|
26 |
|
|
|
27 |
|
|
# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
|
28 |
|
|
typedef struct
|
29 |
|
|
{
|
30 |
|
|
unsigned long int __val[_SIGSET_NWORDS];
|
31 |
|
|
} __sigset_t;
|
32 |
|
|
|
33 |
|
|
#endif
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
/* We only want to define these functions if <signal.h> was actually
|
37 |
|
|
included; otherwise we were included just to define the types. Since we
|
38 |
|
|
are namespace-clean, it wouldn't hurt to define extra macros. But
|
39 |
|
|
trouble can be caused by functions being defined (e.g., any global
|
40 |
|
|
register vars declared later will cause compilation errors). */
|
41 |
|
|
|
42 |
|
|
#if !defined _SIGSET_H_fns && defined _SIGNAL_H
|
43 |
|
|
# define _SIGSET_H_fns 1
|
44 |
|
|
|
45 |
|
|
# ifndef _EXTERN_INLINE
|
46 |
|
|
# define _EXTERN_INLINE extern __inline
|
47 |
|
|
# endif
|
48 |
|
|
|
49 |
|
|
/* Return a mask that includes the bit for SIG only. */
|
50 |
|
|
# define __sigmask(sig) \
|
51 |
|
|
(((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
|
52 |
|
|
|
53 |
|
|
/* Return the word index for SIG. */
|
54 |
|
|
# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
|
55 |
|
|
|
56 |
|
|
# if defined __GNUC__ && __GNUC__ >= 2
|
57 |
|
|
# define __sigemptyset(set) \
|
58 |
|
|
(__extension__ ({ int __cnt = _SIGSET_NWORDS; \
|
59 |
|
|
sigset_t *__set = (set); \
|
60 |
|
|
while (--__cnt >= 0) __set->__val[__cnt] = 0; \
|
61 |
|
|
0; }))
|
62 |
|
|
# define __sigfillset(set) \
|
63 |
|
|
(__extension__ ({ int __cnt = _SIGSET_NWORDS; \
|
64 |
|
|
sigset_t *__set = (set); \
|
65 |
|
|
while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
|
66 |
|
|
0; }))
|
67 |
|
|
|
68 |
|
|
# ifdef __USE_GNU
|
69 |
|
|
/* The POSIX does not specify for handling the whole signal set in one
|
70 |
|
|
command. This is often wanted and so we define three more functions
|
71 |
|
|
here. */
|
72 |
|
|
# define __sigisemptyset(set) \
|
73 |
|
|
(__extension__ ({ int __cnt = _SIGSET_NWORDS; \
|
74 |
|
|
const sigset_t *__set = (set); \
|
75 |
|
|
int __ret = __set->__val[--__cnt]; \
|
76 |
|
|
while (!__ret && --__cnt >= 0) \
|
77 |
|
|
__ret = __set->__val[__cnt]; \
|
78 |
|
|
__ret == 0; }))
|
79 |
|
|
# define __sigandset(dest, left, right) \
|
80 |
|
|
(__extension__ ({ int __cnt = _SIGSET_NWORDS; \
|
81 |
|
|
sigset_t *__dest = (dest); \
|
82 |
|
|
const sigset_t *__left = (left); \
|
83 |
|
|
const sigset_t *__right = (right); \
|
84 |
|
|
while (--__cnt >= 0) \
|
85 |
|
|
__dest->__val[__cnt] = (__left->__val[__cnt] \
|
86 |
|
|
& __right->__val[__cnt]); \
|
87 |
|
|
0; }))
|
88 |
|
|
# define __sigorset(dest, left, right) \
|
89 |
|
|
(__extension__ ({ int __cnt = _SIGSET_NWORDS; \
|
90 |
|
|
sigset_t *__dest = (dest); \
|
91 |
|
|
const sigset_t *__left = (left); \
|
92 |
|
|
const sigset_t *__right = (right); \
|
93 |
|
|
while (--__cnt >= 0) \
|
94 |
|
|
__dest->__val[__cnt] = (__left->__val[__cnt] \
|
95 |
|
|
| __right->__val[__cnt]); \
|
96 |
|
|
0; }))
|
97 |
|
|
# endif
|
98 |
|
|
# endif
|
99 |
|
|
|
100 |
|
|
/* These functions needn't check for a bogus signal number -- error
|
101 |
|
|
checking is done in the non __ versions. */
|
102 |
|
|
|
103 |
|
|
extern int __sigismember (__const __sigset_t *, int);
|
104 |
|
|
extern int __sigaddset (__sigset_t *, int);
|
105 |
|
|
extern int __sigdelset (__sigset_t *, int);
|
106 |
|
|
|
107 |
|
|
# ifdef __USE_EXTERN_INLINES
|
108 |
|
|
# define __SIGSETFN(NAME, BODY, CONST) \
|
109 |
|
|
_EXTERN_INLINE int \
|
110 |
|
|
NAME (CONST __sigset_t *__set, int __sig) \
|
111 |
|
|
{ \
|
112 |
|
|
unsigned long int __mask = __sigmask (__sig); \
|
113 |
|
|
unsigned long int __word = __sigword (__sig); \
|
114 |
|
|
return BODY; \
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
__SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
|
118 |
|
|
__SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
|
119 |
|
|
__SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
|
120 |
|
|
|
121 |
|
|
# undef __SIGSETFN
|
122 |
|
|
# endif
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
#endif /* ! _SIGSET_H_fns. */
|