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