Back to index

glibc  2.9
sigset.h
Go to the documentation of this file.
00001 /* __sig_atomic_t, __sigset_t, and related definitions.  AIX version.
00002    Copyright (C) 1991,1992,1994,1996,1997,2000 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 
00027 typedef struct
00028   {
00029     unsigned int __losigs;
00030     unsigned int __hisigs;
00031   } __sigset_t;
00032 
00033 #endif
00034 
00035 
00036 /* We only want to define these functions if <signal.h> was actually
00037    included; otherwise we were included just to define the types.  Since we
00038    are namespace-clean, it wouldn't hurt to define extra macros.  But
00039    trouble can be caused by functions being defined (e.g., any global
00040    register vars declared later will cause compilation errors).  */
00041 
00042 #if !defined _SIGSET_H_fns && defined _SIGNAL_H
00043 # define _SIGSET_H_fns 1
00044 
00045 # ifndef _EXTERN_INLINE
00046 #  define _EXTERN_INLINE extern __inline
00047 # endif
00048 
00049 /* Return a mask that includes the bit for SIG only.  */
00050 # define __sigmask(sig) \
00051   (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned int))))
00052 
00053 # if defined __GNUC__ && __GNUC__ >= 2
00054 #  define __sigemptyset(set) \
00055   (__extension__ ({ sigset_t *__set = (set);                                \
00056                   __set->__losigs = __set->__hisigs = 0;                    \
00057                   0; }))
00058 #  define __sigfillset(set) \
00059   (__extension__ ({ sigset_t *__set = (set);                                \
00060                   __set->__losigs = __set->__hisigs = ~0u;                  \
00061                   0; }))
00062 
00063 #  ifdef __USE_GNU
00064 /* The POSIX does not specify for handling the whole signal set in one
00065    command.  This is often wanted and so we define three more functions
00066    here.  */
00067 #   define __sigisemptyset(set) \
00068   (__extension__ ({ const sigset_t *__set = (set);                          \
00069                   (__set->__losigs | __set->__hisigs) == 0; }))
00070 #   define __sigandset(dest, left, right) \
00071   (__extension__ ({ sigset_t *__dest = (dest);                              \
00072                   const sigset_t *__left = (left);                          \
00073                   const sigset_t *__right = (right);                        \
00074                   __dest->__losigs = __left->__losigs & __right->__losigs;  \
00075                   __dest->__hisigs = __left->__hisigs & __right->__hisigs;  \
00076                   0; }))
00077 #   define __sigorset(dest, left, right) \
00078   (__extension__ ({ sigset_t *__dest = (dest);                              \
00079                   const sigset_t *__left = (left);                          \
00080                   const sigset_t *__right = (right);                        \
00081                   __dest->__losigs = __left->__losigs | __right->__losigs;  \
00082                   __dest->__hisigs = __left->__hisigs | __right->__hisigs;  \
00083                   0; }))
00084 #  endif
00085 # endif
00086 
00087 /* These functions needn't check for a bogus signal number -- error
00088    checking is done in the non __ versions.  */
00089 
00090 extern int __sigismember (__const __sigset_t *, int);
00091 extern int __sigaddset (__sigset_t *, int);
00092 extern int __sigdelset (__sigset_t *, int);
00093 
00094 # ifdef __USE_EXTERN_INLINES
00095 _EXTERN_INLINE int
00096 __sigismember (__const __sigset_t *__set, int __sig)
00097 {
00098   unsigned int __mask = __sigmask (__sig);
00099 
00100   return ((__sig < 33 ? __set->__losigs : __set->__hisigs) & __mask ) ? 1 : 0;
00101 }
00102 
00103 _EXTERN_INLINE int
00104 __sigaddset (__sigset_t *__set, int __sig)
00105 {
00106   unsigned int __mask = __sigmask (__sig);
00107 
00108   (__sig < 33 ? __set->__losigs : __set->__hisigs) |= __mask;
00109 
00110   return 0;
00111 }
00112 
00113 _EXTERN_INLINE int
00114 __sigdelset (__sigset_t *__set, int __sig)
00115 {
00116   unsigned int __mask = __sigmask (__sig);
00117 
00118   (__sig < 33 ? __set->__losigs : __set->__hisigs) &= ~__mask;
00119 
00120   return 0;
00121 }
00122 # endif
00123 
00124 
00125 #endif /* ! _SIGSET_H_fns.  */