1/* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
2 Copyright (C) 1991-2015 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 _SIGSET_H_types
20# define _SIGSET_H_types 1
21
22typedef int __sig_atomic_t;
23
24/* A `sigset_t' has a bit for each signal. */
25
26# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
27typedef struct
28 {
29 unsigned long int __val[_SIGSET_NWORDS];
30 } __sigset_t;
31
32#endif
33
34
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). */
40
41#if !defined _SIGSET_H_fns && defined _SIGNAL_H
42# define _SIGSET_H_fns 1
43
44# ifndef _EXTERN_INLINE
45# define _EXTERN_INLINE __extern_inline
46# endif
47
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))))
51
52/* Return the word index for SIG. */
53# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
54
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; }))
66
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
98
99/* These functions needn't check for a bogus signal number -- error
100 checking is done in the non __ versions. */
101
102extern int __sigismember (const __sigset_t *, int);
103extern int __sigaddset (__sigset_t *, int);
104extern int __sigdelset (__sigset_t *, int);
105
106# ifdef __USE_EXTERN_INLINES
107# define __SIGSETFN(NAME, BODY, CONST) \
108 _EXTERN_INLINE int \
109 NAME (CONST __sigset_t *__set, int __sig) \
110 { \
111 unsigned long int __mask = __sigmask (__sig); \
112 unsigned long int __word = __sigword (__sig); \
113 return BODY; \
114 }
115
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), )
119
120# undef __SIGSETFN
121# endif
122
123
124#endif /* ! _SIGSET_H_fns. */
125