1/* Internal sigset_t definition.
2 Copyright (C) 2022-2024 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 <https://www.gnu.org/licenses/>. */
18
19#ifndef _INTERNAL_SIGSET_H
20#define _INTERNAL_SIGSET_H
21
22#include <sigsetops.h>
23
24typedef struct
25{
26 unsigned long int __val[__NSIG_WORDS];
27} internal_sigset_t;
28
29static inline void
30internal_sigset_from_sigset (internal_sigset_t *iset, const sigset_t *set)
31{
32 int cnt = __NSIG_WORDS;
33 while (--cnt >= 0)
34 iset->__val[cnt] = set->__val[cnt];
35}
36
37static inline void
38internal_sigemptyset (internal_sigset_t *set)
39{
40 int cnt = __NSIG_WORDS;
41 while (--cnt >= 0)
42 set->__val[cnt] = 0;
43}
44
45static inline void
46internal_sigfillset (internal_sigset_t *set)
47{
48 int cnt = __NSIG_WORDS;
49 while (--cnt >= 0)
50 set->__val[cnt] = ~0UL;
51}
52
53static inline int
54internal_sigisemptyset (const internal_sigset_t *set)
55{
56 int cnt = __NSIG_WORDS;
57 int ret = set->__val[--cnt];
58 while (ret == 0 && --cnt >= 0)
59 ret = set->__val[cnt];
60 return ret == 0;
61}
62
63static inline void
64internal_sigandset (internal_sigset_t *dest, const internal_sigset_t *left,
65 const internal_sigset_t *right)
66{
67 int cnt = __NSIG_WORDS;
68 while (--cnt >= 0)
69 dest->__val[cnt] = left->__val[cnt] & right->__val[cnt];
70}
71
72static inline void
73internal_sigorset (internal_sigset_t *dest, const internal_sigset_t *left,
74 const internal_sigset_t *right)
75{
76 int cnt = __NSIG_WORDS;
77 while (--cnt >= 0)
78 dest->__val[cnt] = left->__val[cnt] | right->__val[cnt];
79}
80
81static inline int
82internal_sigismember (const internal_sigset_t *set, int sig)
83{
84 unsigned long int mask = __sigmask (sig);
85 unsigned long int word = __sigword (sig);
86 return set->__val[word] & mask ? 1 : 0;
87}
88
89static inline void
90internal_sigaddset (internal_sigset_t *set, int sig)
91{
92 unsigned long int mask = __sigmask (sig);
93 unsigned long int word = __sigword (sig);
94 set->__val[word] |= mask;
95}
96
97static inline void
98internal_sigdelset (internal_sigset_t *set, int sig)
99{
100 unsigned long int mask = __sigmask (sig);
101 unsigned long int word = __sigword (sig);
102 set->__val[word] &= ~mask;
103}
104
105#endif /* _INTERNAL_SIGSET_H */
106

source code of glibc/sysdeps/unix/sysv/linux/internal-sigset.h