sigsetops.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* __sigset_t manipulators. Linux version.
  2. Copyright (C) 1991-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SIGSETOPS_H
  16. #define _SIGSETOPS_H 1
  17. #include <signal.h>
  18. /* Return a mask that includes the bit for SIG only. */
  19. # define __sigmask(sig) \
  20. (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
  21. /* Return the word index for SIG. */
  22. # define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
  23. # define __sigemptyset(set) \
  24. (__extension__ ({ \
  25. int __cnt = _SIGSET_NWORDS; \
  26. sigset_t *__set = (set); \
  27. while (--__cnt >= 0) \
  28. __set->__val[__cnt] = 0; \
  29. (void)0; \
  30. }))
  31. # define __sigfillset(set) \
  32. (__extension__ ({ \
  33. int __cnt = _SIGSET_NWORDS; \
  34. sigset_t *__set = (set); \
  35. while (--__cnt >= 0) \
  36. __set->__val[__cnt] = ~0UL; \
  37. (void)0; \
  38. }))
  39. # define __sigisemptyset(set) \
  40. (__extension__ ({ \
  41. int __cnt = _SIGSET_NWORDS; \
  42. const sigset_t *__set = (set); \
  43. int __ret = __set->__val[--__cnt]; \
  44. while (!__ret && --__cnt >= 0) \
  45. __ret = __set->__val[__cnt]; \
  46. __ret == 0; \
  47. }))
  48. # define __sigandset(dest, left, right) \
  49. (__extension__ ({ \
  50. int __cnt = _SIGSET_NWORDS; \
  51. sigset_t *__dest = (dest); \
  52. const sigset_t *__left = (left); \
  53. const sigset_t *__right = (right); \
  54. while (--__cnt >= 0) \
  55. __dest->__val[__cnt] = (__left->__val[__cnt] \
  56. & __right->__val[__cnt]); \
  57. (void)0; \
  58. }))
  59. # define __sigorset(dest, left, right) \
  60. (__extension__ ({ \
  61. int __cnt = _SIGSET_NWORDS; \
  62. sigset_t *__dest = (dest); \
  63. const sigset_t *__left = (left); \
  64. const sigset_t *__right = (right); \
  65. while (--__cnt >= 0) \
  66. __dest->__val[__cnt] = (__left->__val[__cnt] \
  67. | __right->__val[__cnt]); \
  68. (void)0; \
  69. }))
  70. /* These macros needn't check for a bogus signal number;
  71. error checking is done in the non-__ versions. */
  72. # define __sigismember(set, sig) \
  73. (__extension__ ({ \
  74. unsigned long int __mask = __sigmask (sig); \
  75. unsigned long int __word = __sigword (sig); \
  76. (set)->__val[__word] & __mask ? 1 : 0; \
  77. }))
  78. # define __sigaddset(set, sig) \
  79. (__extension__ ({ \
  80. unsigned long int __mask = __sigmask (sig); \
  81. unsigned long int __word = __sigword (sig); \
  82. (set)->__val[__word] |= __mask; \
  83. (void)0; \
  84. }))
  85. # define __sigdelset(set, sig) \
  86. (__extension__ ({ \
  87. unsigned long int __mask = __sigmask (sig); \
  88. unsigned long int __word = __sigword (sig); \
  89. (set)->__val[__word] &= ~__mask; \
  90. (void)0; \
  91. }))
  92. #endif /* bits/sigsetops.h */