sigset.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
  2. Copyright (C) 1991, 1992, 1994, 1996, 1997 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 Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #ifndef _SIGSET_H_types
  17. # define _SIGSET_H_types 1
  18. typedef int __sig_atomic_t;
  19. /* A `sigset_t' has a bit for each signal. */
  20. # define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
  21. typedef struct
  22. {
  23. unsigned long int __val[_SIGSET_NWORDS];
  24. } __sigset_t;
  25. #endif
  26. /* We only want to define these functions if <signal.h> was actually
  27. included; otherwise we were included just to define the types. Since we
  28. are namespace-clean, it wouldn't hurt to define extra macros. But
  29. trouble can be caused by functions being defined (e.g., any global
  30. register vars declared later will cause compilation errors). */
  31. #if !defined _SIGSET_H_fns && defined _SIGNAL_H
  32. # define _SIGSET_H_fns 1
  33. # ifndef _EXTERN_INLINE
  34. # define _EXTERN_INLINE extern __inline
  35. # endif
  36. /* Return a mask that includes the bit for SIG only. */
  37. # define __sigmask(sig) \
  38. (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
  39. /* Return the word index for SIG. */
  40. # define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
  41. # if defined __GNUC__ && __GNUC__ >= 2
  42. # define __sigemptyset(set) \
  43. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  44. sigset_t *__set = (set); \
  45. while (--__cnt >= 0) __set->__val[__cnt] = 0; \
  46. 0; }))
  47. # define __sigfillset(set) \
  48. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  49. sigset_t *__set = (set); \
  50. while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
  51. 0; }))
  52. # ifdef __USE_GNU
  53. /* The POSIX does not specify for handling the whole signal set in one
  54. command. This is often wanted and so we define three more functions
  55. here. */
  56. # define __sigisemptyset(set) \
  57. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  58. const sigset_t *__set = (set); \
  59. int __ret = __set->__val[--__cnt]; \
  60. while (!__ret && --__cnt >= 0) \
  61. __ret = __set->__val[__cnt]; \
  62. __ret == 0; }))
  63. # define __sigandset(dest, left, right) \
  64. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  65. sigset_t *__dest = (dest); \
  66. const sigset_t *__left = (left); \
  67. const sigset_t *__right = (right); \
  68. while (--__cnt >= 0) \
  69. __dest->__val[__cnt] = (__left->__val[__cnt] \
  70. & __right->__val[__cnt]); \
  71. 0; }))
  72. # define __sigorset(dest, left, right) \
  73. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  74. sigset_t *__dest = (dest); \
  75. const sigset_t *__left = (left); \
  76. const sigset_t *__right = (right); \
  77. while (--__cnt >= 0) \
  78. __dest->__val[__cnt] = (__left->__val[__cnt] \
  79. | __right->__val[__cnt]); \
  80. 0; }))
  81. # endif
  82. # endif
  83. __BEGIN_DECLS
  84. /* These functions needn't check for a bogus signal number -- error
  85. checking is done in the non __ versions. */
  86. extern int __sigismember (__const __sigset_t *, int);
  87. extern int __sigaddset (__sigset_t *, int);
  88. extern int __sigdelset (__sigset_t *, int);
  89. # ifdef __USE_EXTERN_INLINES
  90. # define __SIGSETFN(NAME, BODY, CONST) \
  91. _EXTERN_INLINE int \
  92. NAME (CONST __sigset_t *__set, int __sig) \
  93. { \
  94. unsigned long int __mask = __sigmask (__sig); \
  95. unsigned long int __word = __sigword (__sig); \
  96. return BODY; \
  97. }
  98. __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
  99. __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
  100. __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  101. # undef __SIGSETFN
  102. # endif
  103. __END_DECLS
  104. #endif /* ! _SIGSET_H_fns. */