1/* __sigset_t manipulators. Linux version.
2 Copyright (C) 1991-2018 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, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SIGSETOPS_H
20#define _SIGSETOPS_H 1
21
22#include <signal.h>
23
24/* Return a mask that includes the bit for SIG only. */
25# define __sigmask(sig) \
26 (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
27
28/* Return the word index for SIG. */
29# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
30
31# define __sigemptyset(set) \
32 (__extension__ ({ \
33 int __cnt = _SIGSET_NWORDS; \
34 sigset_t *__set = (set); \
35 while (--__cnt >= 0) \
36 __set->__val[__cnt] = 0; \
37 (void)0; \
38 }))
39
40# define __sigfillset(set) \
41 (__extension__ ({ \
42 int __cnt = _SIGSET_NWORDS; \
43 sigset_t *__set = (set); \
44 while (--__cnt >= 0) \
45 __set->__val[__cnt] = ~0UL; \
46 (void)0; \
47 }))
48
49# define __sigisemptyset(set) \
50 (__extension__ ({ \
51 int __cnt = _SIGSET_NWORDS; \
52 const sigset_t *__set = (set); \
53 int __ret = __set->__val[--__cnt]; \
54 while (!__ret && --__cnt >= 0) \
55 __ret = __set->__val[__cnt]; \
56 __ret == 0; \
57 }))
58
59# define __sigandset(dest, left, right) \
60 (__extension__ ({ \
61 int __cnt = _SIGSET_NWORDS; \
62 sigset_t *__dest = (dest); \
63 const sigset_t *__left = (left); \
64 const sigset_t *__right = (right); \
65 while (--__cnt >= 0) \
66 __dest->__val[__cnt] = (__left->__val[__cnt] \
67 & __right->__val[__cnt]); \
68 (void)0; \
69 }))
70
71# define __sigorset(dest, left, right) \
72 (__extension__ ({ \
73 int __cnt = _SIGSET_NWORDS; \
74 sigset_t *__dest = (dest); \
75 const sigset_t *__left = (left); \
76 const sigset_t *__right = (right); \
77 while (--__cnt >= 0) \
78 __dest->__val[__cnt] = (__left->__val[__cnt] \
79 | __right->__val[__cnt]); \
80 (void)0; \
81 }))
82
83/* These macros needn't check for a bogus signal number;
84 error checking is done in the non-__ versions. */
85# define __sigismember(set, sig) \
86 (__extension__ ({ \
87 unsigned long int __mask = __sigmask (sig); \
88 unsigned long int __word = __sigword (sig); \
89 (set)->__val[__word] & __mask ? 1 : 0; \
90 }))
91
92# define __sigaddset(set, sig) \
93 (__extension__ ({ \
94 unsigned long int __mask = __sigmask (sig); \
95 unsigned long int __word = __sigword (sig); \
96 (set)->__val[__word] |= __mask; \
97 (void)0; \
98 }))
99
100# define __sigdelset(set, sig) \
101 (__extension__ ({ \
102 unsigned long int __mask = __sigmask (sig); \
103 unsigned long int __word = __sigword (sig); \
104 (set)->__val[__word] &= ~__mask; \
105 (void)0; \
106 }))
107
108#endif /* bits/sigsetops.h */
109