Back to index

glibc  2.9
sigset.h
Go to the documentation of this file.
00001 /* __sig_atomic_t, __sigset_t, and related definitions.  SVR4 version.
00002    Copyright (C) 1994-1996, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef       _SIGSET_H_types
00021 #define       _SIGSET_H_types      1
00022 
00023 typedef int __sig_atomic_t;
00024 
00025 /* A `sigset_t' has a bit for each signal.  */
00026 typedef struct
00027   {
00028     unsigned long int __sigbits[4];
00029   } __sigset_t;
00030 
00031 #endif /* ! _SIGSET_H_types */
00032 
00033 /* We only want to define these functions if <signal.h> was actually
00034    included; otherwise we were included just to define the types.  Since we
00035    are namespace-clean, it wouldn't hurt to define extra macros.  But
00036    trouble can be caused by functions being defined (e.g., any global
00037    register vars declared later will cause compilation errors).  */
00038 
00039 #if !defined (_SIGSET_H_fns) && defined (_SIGNAL_H)
00040 #define _SIGSET_H_fns 1
00041 
00042 /* Return a mask that includes SIG only.  */
00043 #define       __sigmask(sig)       (1 << ((sig) - 1))
00044 
00045 
00046 /* It's easier to assume 8-bit bytes than to get CHAR_BIT.  */
00047 #define       __NSSBITS     (sizeof (unsigned long int) * 8)
00048 #define       __SSELT(s)    ((s) / __NSSBITS)
00049 #define       __SSMASK(s)   (1 << ((s) % __NSSBITS))
00050 
00051 #ifdef __USE_EXTERN_INLINES
00052 # ifndef _EXTERN_INLINE
00053 #  define _EXTERN_INLINE    extern __inline
00054 # endif
00055 
00056 _EXTERN_INLINE int
00057 __sigemptyset (__sigset_t *__set)
00058 {
00059   __set->__sigbits[0] = __set->__sigbits[1] =
00060     __set->__sigbits[2] = __set->__sigbits[3] = 0L;
00061   return 0;
00062 }
00063 
00064 _EXTERN_INLINE int
00065 __sigfillset (__sigset_t *__set)
00066 {
00067   /* SVR4 has a system call for `sigfillset' (!), and it only sets the bits
00068      for signals [1,31].  Setting bits for unimplemented signals seems
00069      harmless (and we will find out if it really is).  */
00070   __set->__sigbits[0] = __set->__sigbits[1] =
00071     __set->__sigbits[2] = __set->__sigbits[3] = ~0L;
00072   return 0;
00073 }
00074 
00075 _EXTERN_INLINE int
00076 __sigaddset (__sigset_t *__set, int __sig)
00077 {
00078   __set->__sigbits[__SSELT (__sig)] |= __SSMASK (__sig);
00079   return 0;
00080 }
00081 
00082 _EXTERN_INLINE int
00083 __sigdelset (__sigset_t *__set, int __sig)
00084 {
00085   __set->__sigbits[__SSELT (__sig)] &= ~__SSMASK (__sig);
00086   return 0;
00087 }
00088 
00089 _EXTERN_INLINE int
00090 __sigismember (__const __sigset_t *__set, int __sig)
00091 {
00092   if (__set->__sigbits[__SSELT (__sig)] & __SSMASK (__sig))
00093     return 1;
00094   return 0;
00095 }
00096 #endif /* use extern inlines.  */
00097 
00098 #endif /* ! _SIGSET_H_fns */