Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / bits / sigset.h
blobaf4ae837f2ad8e2fe70137040d05c2965158ce18
1 /* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
2 Copyright (C) 1991-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _SIGSET_H_types
20 # define _SIGSET_H_types 1
22 typedef int __sig_atomic_t;
24 /* A `sigset_t' has a bit for each signal. */
26 # define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
27 typedef struct
29 unsigned long int __val[_SIGSET_NWORDS];
30 } __sigset_t;
32 #endif
35 /* We only want to define these functions if <signal.h> was actually
36 included; otherwise we were included just to define the types. Since we
37 are namespace-clean, it wouldn't hurt to define extra macros. But
38 trouble can be caused by functions being defined (e.g., any global
39 register vars declared later will cause compilation errors). */
41 #if !defined _SIGSET_H_fns && defined _SIGNAL_H
42 # define _SIGSET_H_fns 1
44 # ifndef _EXTERN_INLINE
45 # define _EXTERN_INLINE __extern_inline
46 # endif
48 /* Return a mask that includes the bit for SIG only. */
49 # define __sigmask(sig) \
50 (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
52 /* Return the word index for SIG. */
53 # define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
55 # if defined __GNUC__ && __GNUC__ >= 2
56 # define __sigemptyset(set) \
57 (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
58 sigset_t *__set = (set); \
59 while (--__cnt >= 0) __set->__val[__cnt] = 0; \
60 0; }))
61 # define __sigfillset(set) \
62 (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
63 sigset_t *__set = (set); \
64 while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
65 0; }))
67 # ifdef __USE_GNU
68 /* The POSIX does not specify for handling the whole signal set in one
69 command. This is often wanted and so we define three more functions
70 here. */
71 # define __sigisemptyset(set) \
72 (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
73 const sigset_t *__set = (set); \
74 int __ret = __set->__val[--__cnt]; \
75 while (!__ret && --__cnt >= 0) \
76 __ret = __set->__val[__cnt]; \
77 __ret == 0; }))
78 # define __sigandset(dest, left, right) \
79 (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
80 sigset_t *__dest = (dest); \
81 const sigset_t *__left = (left); \
82 const sigset_t *__right = (right); \
83 while (--__cnt >= 0) \
84 __dest->__val[__cnt] = (__left->__val[__cnt] \
85 & __right->__val[__cnt]); \
86 0; }))
87 # define __sigorset(dest, left, right) \
88 (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
89 sigset_t *__dest = (dest); \
90 const sigset_t *__left = (left); \
91 const sigset_t *__right = (right); \
92 while (--__cnt >= 0) \
93 __dest->__val[__cnt] = (__left->__val[__cnt] \
94 | __right->__val[__cnt]); \
95 0; }))
96 # endif
97 # endif
99 /* These functions needn't check for a bogus signal number -- error
100 checking is done in the non __ versions. */
102 extern int __sigismember (const __sigset_t *, int);
103 extern int __sigaddset (__sigset_t *, int);
104 extern int __sigdelset (__sigset_t *, int);
106 # ifdef __USE_EXTERN_INLINES
107 # define __SIGSETFN(NAME, BODY, CONST) \
108 _EXTERN_INLINE int \
109 NAME (CONST __sigset_t *__set, int __sig) \
111 unsigned long int __mask = __sigmask (__sig); \
112 unsigned long int __word = __sigword (__sig); \
113 return BODY; \
116 __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, const)
117 __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
118 __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
120 # undef __SIGSETFN
121 # endif
124 #endif /* ! _SIGSET_H_fns. */