sigset.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __SIGSET_H__
  2. #define __SIGSET_H__
  3. /* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
  4. Copyright (C) 1991, 1992, 1994, 1996, 1997, 2007
  5. Free Software Foundation, Inc.
  6. This file is part of the GNU C Library.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  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. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; if not, write to the Free
  17. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA. */
  19. #define _SIGSET_H_types 1
  20. #define _SIGSET_H_fns 1
  21. typedef int __sig_atomic_t;
  22. /* A `sigset_t' has a bit for each signal. */
  23. # define _SIGSET_NWORDS (64 / (8 * sizeof (unsigned long int)))
  24. typedef struct
  25. {
  26. unsigned long int __val[_SIGSET_NWORDS];
  27. } __sigset_t;
  28. /* Return a mask that includes the bit for SIG only. */
  29. # define __sigmask(sig) \
  30. (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
  31. /* Return the word index for SIG. */
  32. # define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
  33. # define __sigemptyset(set) \
  34. ({ int __cnt = _SIGSET_NWORDS; \
  35. __sigset_t *__set = (set); \
  36. while (--__cnt >= 0) __set->__val[__cnt] = 0; \
  37. 0; })
  38. # define __sigfillset(set) \
  39. ({ int __cnt = _SIGSET_NWORDS; \
  40. __sigset_t *__set = (set); \
  41. while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
  42. 0; })
  43. # define __sigcopyset(set, src) \
  44. ({ int __cnt = _SIGSET_NWORDS; \
  45. __sigset_t *__set = (set); \
  46. __sigset_t *__src = (src); \
  47. while (--__cnt >= 0) __set->__val[__cnt] = __src->__val[__cnt]; \
  48. 0; })
  49. /* These functions needn't check for a bogus signal number -- error
  50. checking is done in the non __ versions. */
  51. # define __SIGSETFN(NAME, BODY, CONST) \
  52. static inline int \
  53. NAME (CONST __sigset_t *__set, int __sig) \
  54. { \
  55. unsigned long int __mask = __sigmask (__sig); \
  56. unsigned long int __word = __sigword (__sig); \
  57. return BODY; \
  58. }
  59. __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
  60. __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
  61. __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  62. # undef __SIGSETFN
  63. #endif /* __SIGSET_H__ */