sigset-cvt-mask.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Convert between lowlevel sigmask and libc representation of sigset_t.
  2. Generic version.
  3. Copyright (C) 1998-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Joe Keane <jgk@jgk.org>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. /* Convert between an old-style 32-bit signal mask and a POSIX sigset_t. */
  18. #include <sigsetops.h>
  19. /* Perform *SET = MASK. Unused bits of *SET are set to 0.
  20. Returns zero for success or -1 for errors (from sigaddset/sigemptyset). */
  21. static inline int __attribute__ ((unused))
  22. sigset_set_old_mask (sigset_t *set, int mask)
  23. {
  24. if (sizeof (__sigset_t) == sizeof (unsigned int))
  25. *set = (unsigned int) mask;
  26. else
  27. {
  28. unsigned int __sig;
  29. if (__sigemptyset (set) < 0)
  30. return -1;
  31. for (__sig = 1; __sig < NSIG && __sig <= sizeof (mask) * 8; __sig++)
  32. if (mask & sigmask (__sig))
  33. if (__sigaddset (set, __sig) < 0)
  34. return -1;
  35. }
  36. return 0;
  37. }
  38. /* Return the sigmask corresponding to *SET.
  39. Unused bits of *SET are thrown away. */
  40. static inline int __attribute__ ((unused))
  41. sigset_get_old_mask (const sigset_t *set)
  42. {
  43. if (sizeof (sigset_t) == sizeof (unsigned int))
  44. return (unsigned int) *set;
  45. else
  46. {
  47. unsigned int mask = 0;
  48. unsigned int sig;
  49. for (sig = 1; sig < NSIG && sig <= sizeof (mask) * 8; sig++)
  50. if (__sigismember (set, sig))
  51. mask |= sigmask (sig);
  52. return mask;
  53. }
  54. }