sigact.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* $OpenBSD: sigaction.c,v 1.4 2001/01/22 18:01:48 millert Exp $ */
  2. /****************************************************************************
  3. * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
  4. * *
  5. * Permission is hereby granted, free of charge, to any person obtaining a *
  6. * copy of this software and associated documentation files (the *
  7. * "Software"), to deal in the Software without restriction, including *
  8. * without limitation the rights to use, copy, modify, merge, publish, *
  9. * distribute, distribute with modifications, sublicense, and/or sell *
  10. * copies of the Software, and to permit persons to whom the Software is *
  11. * furnished to do so, subject to the following conditions: *
  12. * *
  13. * The above copyright notice and this permission notice shall be included *
  14. * in all copies or substantial portions of the Software. *
  15. * *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  19. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  22. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  23. * *
  24. * Except as contained in this notice, the name(s) of the above copyright *
  25. * holders shall not be used in advertising or otherwise to promote the *
  26. * sale, use or other dealings in this Software without prior written *
  27. * authorization. *
  28. ****************************************************************************/
  29. /****************************************************************************
  30. * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
  31. * and: Eric S. Raymond <esr@snark.thyrsus.com> *
  32. ****************************************************************************/
  33. /* OPENBSD ORIGINAL: lib/libcurses/base/sigaction.c */
  34. #include "includes.h"
  35. #include <errno.h>
  36. #include <signal.h>
  37. #include "sigact.h"
  38. /* This file provides sigaction() emulation using sigvec() */
  39. /* Use only if this is non POSIX system */
  40. #if !HAVE_SIGACTION && HAVE_SIGVEC
  41. int
  42. sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact)
  43. {
  44. return sigvec(sig, sigact ? &sigact->sv : NULL,
  45. osigact ? &osigact->sv : NULL);
  46. }
  47. int
  48. sigemptyset (sigset_t *mask)
  49. {
  50. if (!mask) {
  51. errno = EINVAL;
  52. return -1;
  53. }
  54. *mask = 0;
  55. return 0;
  56. }
  57. int
  58. sigprocmask (int mode, sigset_t *mask, sigset_t *omask)
  59. {
  60. sigset_t current = sigsetmask(0);
  61. if (!mask) {
  62. errno = EINVAL;
  63. return -1;
  64. }
  65. if (omask)
  66. *omask = current;
  67. if (mode == SIG_BLOCK)
  68. current |= *mask;
  69. else if (mode == SIG_UNBLOCK)
  70. current &= ~*mask;
  71. else if (mode == SIG_SETMASK)
  72. current = *mask;
  73. sigsetmask(current);
  74. return 0;
  75. }
  76. int
  77. sigsuspend (sigset_t *mask)
  78. {
  79. if (!mask) {
  80. errno = EINVAL;
  81. return -1;
  82. }
  83. return sigpause(*mask);
  84. }
  85. int
  86. sigdelset (sigset_t *mask, int sig)
  87. {
  88. if (!mask) {
  89. errno = EINVAL;
  90. return -1;
  91. }
  92. *mask &= ~sigmask(sig);
  93. return 0;
  94. }
  95. int
  96. sigaddset (sigset_t *mask, int sig)
  97. {
  98. if (!mask) {
  99. errno = EINVAL;
  100. return -1;
  101. }
  102. *mask |= sigmask(sig);
  103. return 0;
  104. }
  105. int
  106. sigismember (sigset_t *mask, int sig)
  107. {
  108. if (!mask) {
  109. errno = EINVAL;
  110. return -1;
  111. }
  112. return (*mask & sigmask(sig)) != 0;
  113. }
  114. #endif