sigset.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #define ____sigset_t_defined
  22. typedef int __sig_atomic_t;
  23. /* A `sigset_t' has a bit for each signal. */
  24. #define _SIGSET_NWORDS (64 / (8 * sizeof(unsigned long int)))
  25. typedef struct {
  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) (((unsigned long int)1) << (((sig) - 1) % (8 * sizeof(unsigned long int))))
  30. /* Return the word index for SIG. */
  31. #define __sigword(sig) (((sig) - 1) / (8 * sizeof(unsigned long int)))
  32. #define __sigemptyset(set) \
  33. ({ \
  34. int __cnt = _SIGSET_NWORDS; \
  35. _sigset_t* __set = (set); \
  36. while (--__cnt >= 0) { \
  37. __set->__val[__cnt] = 0; \
  38. } \
  39. 0; \
  40. })
  41. #define __sigfillset(set) \
  42. ({ \
  43. int __cnt = _SIGSET_NWORDS; \
  44. _sigset_t* __set = (set); \
  45. while (--__cnt >= 0) { \
  46. __set->__val[__cnt] = ~0UL; \
  47. } \
  48. 0; \
  49. })
  50. #define __sigcopyset(set, src) \
  51. ({ \
  52. int __cnt = _SIGSET_NWORDS; \
  53. _sigset_t* __set = (set); \
  54. _sigset_t* __src = (src); \
  55. while (--__cnt >= 0) { \
  56. __set->__val[__cnt] = __src->__val[__cnt]; \
  57. } \
  58. 0; \
  59. })
  60. /* These functions needn't check for a bogus signal number -- error
  61. checking is done in the non __ versions. */
  62. #define __SIGSETFN(NAME, BODY, CONST) \
  63. static inline int NAME(CONST _sigset_t* __set, int __sig) { \
  64. unsigned long int __mask = __sigmask(__sig); \
  65. unsigned long int __word = __sigword(__sig); \
  66. return BODY; \
  67. }
  68. __SIGSETFN(__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
  69. __SIGSETFN(__sigaddset, ((__set->__val[__word] |= __mask), 0), )
  70. __SIGSETFN(__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  71. #undef __SIGSETFN
  72. #endif /* __SIGSET_H__ */