1    	/* __sig_atomic_t, __sigset_t, and related definitions.  Linux version.
2    	   Copyright (C) 1991, 1992, 1994, 1996, 1997, 2007
3    	   Free Software Foundation, Inc.
4    	   This file is part of the GNU C Library.
5    	
6    	   The GNU C Library is free software; you can redistribute it and/or
7    	   modify it under the terms of the GNU Lesser General Public
8    	   License as published by the Free Software Foundation; either
9    	   version 2.1 of the License, or (at your option) any later version.
10   	
11   	   The GNU C Library is distributed in the hope that it will be useful,
12   	   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   	   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   	   Lesser General Public License for more details.
15   	
16   	   You should have received a copy of the GNU Lesser General Public
17   	   License along with the GNU C Library; if not, write to the Free
18   	   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   	   02111-1307 USA.  */
20   	
21   	#ifndef	_SIGSET_H_types
22   	# define _SIGSET_H_types	1
23   	
24   	typedef int __sig_atomic_t;
25   	
26   	/* A `sigset_t' has a bit for each signal.  */
27   	
28   	# define _SIGSET_NWORDS	(1024 / (8 * sizeof (unsigned long int)))
29   	typedef struct
30   	  {
31   	    unsigned long int __val[_SIGSET_NWORDS];
32   	  } __sigset_t;
33   	
34   	#endif
35   	
36   	
37   	/* We only want to define these functions if <signal.h> was actually
38   	   included; otherwise we were included just to define the types.  Since we
39   	   are namespace-clean, it wouldn't hurt to define extra macros.  But
40   	   trouble can be caused by functions being defined (e.g., any global
41   	   register vars declared later will cause compilation errors).  */
42   	
43   	#if !defined _SIGSET_H_fns && defined _SIGNAL_H
44   	# define _SIGSET_H_fns 1
45   	
46   	# ifndef _EXTERN_INLINE
47   	#  define _EXTERN_INLINE __extern_inline
48   	# endif
49   	
50   	/* Return a mask that includes the bit for SIG only.  */
51   	# define __sigmask(sig) \
52   	  (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
53   	
54   	/* Return the word index for SIG.  */
55   	# define __sigword(sig)	(((sig) - 1) / (8 * sizeof (unsigned long int)))
56   	
57   	# if defined __GNUC__ && __GNUC__ >= 2
58   	#  define __sigemptyset(set) \
59   	  (__extension__ ({ int __cnt = _SIGSET_NWORDS;				      \
60   			    sigset_t *__set = (set);				      \
61   			    while (--__cnt >= 0) __set->__val[__cnt] = 0;	      \
62   			    0; }))
63   	#  define __sigfillset(set) \
64   	  (__extension__ ({ int __cnt = _SIGSET_NWORDS;				      \
65   			    sigset_t *__set = (set);				      \
66   			    while (--__cnt >= 0) __set->__val[__cnt] = ~0UL;	      \
67   			    0; }))
68   	
69   	#  ifdef __USE_GNU
70   	/* The POSIX does not specify for handling the whole signal set in one
71   	   command.  This is often wanted and so we define three more functions
72   	   here.  */
73   	#   define __sigisemptyset(set) \
74   	  (__extension__ ({ int __cnt = _SIGSET_NWORDS;				      \
75   			    const sigset_t *__set = (set);			      \
76   			    int __ret = __set->__val[--__cnt];			      \
77   			    while (!__ret && --__cnt >= 0)			      \
78   				__ret = __set->__val[__cnt];			      \
79   			    __ret == 0; }))
80   	#   define __sigandset(dest, left, right) \
81   	  (__extension__ ({ int __cnt = _SIGSET_NWORDS;				      \
82   			    sigset_t *__dest = (dest);				      \
83   			    const sigset_t *__left = (left);			      \
84   			    const sigset_t *__right = (right);			      \
85   			    while (--__cnt >= 0)				      \
86   			      __dest->__val[__cnt] = (__left->__val[__cnt]	      \
87   						      & __right->__val[__cnt]);	      \
88   			    0; }))
89   	#   define __sigorset(dest, left, right) \
90   	  (__extension__ ({ int __cnt = _SIGSET_NWORDS;				      \
91   			    sigset_t *__dest = (dest);				      \
92   			    const sigset_t *__left = (left);			      \
93   			    const sigset_t *__right = (right);			      \
94   			    while (--__cnt >= 0)				      \
95   			      __dest->__val[__cnt] = (__left->__val[__cnt]	      \
96   						      | __right->__val[__cnt]);	      \
97   			    0; }))
98   	#  endif
99   	# endif
100  	
101  	/* These functions needn't check for a bogus signal number -- error
102  	   checking is done in the non __ versions.  */
103  	
104  	extern int __sigismember (__const __sigset_t *, int);
105  	extern int __sigaddset (__sigset_t *, int);
106  	extern int __sigdelset (__sigset_t *, int);
107  	
108  	# ifdef __USE_EXTERN_INLINES
109  	#  define __SIGSETFN(NAME, BODY, CONST)					      \
110  	  _EXTERN_INLINE int							      \
111  	  NAME (CONST __sigset_t *__set, int __sig)				      \
112  	  {									      \
113  	    unsigned long int __mask = __sigmask (__sig);			      \
114  	    unsigned long int __word = __sigword (__sig);			      \
115  	    return BODY;							      \
116  	  }
117  	
118  	__SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
119  	__SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
120  	__SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
121  	
122  	#  undef __SIGSETFN
123  	# endif
124  	
125  	
126  	#endif /* ! _SIGSET_H_fns.  */
127