]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/internal-sigset.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / internal-sigset.h
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
24 typedef struct
25 {
26 unsigned long int __val[__NSIG_WORDS];
27 } internal_sigset_t;
28
29 static inline void
30 internal_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
37 static inline void
38 internal_sigemptyset (internal_sigset_t *set)
39 {
40 int cnt = __NSIG_WORDS;
41 while (--cnt >= 0)
42 set->__val[cnt] = 0;
43 }
44
45 static inline void
46 internal_sigfillset (internal_sigset_t *set)
47 {
48 int cnt = __NSIG_WORDS;
49 while (--cnt >= 0)
50 set->__val[cnt] = ~0UL;
51 }
52
53 static inline int
54 internal_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
63 static inline void
64 internal_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
72 static inline void
73 internal_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
81 static inline int
82 internal_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
89 static inline void
90 internal_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
97 static inline void
98 internal_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 */