sigset.c 892 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <signal.h>
  2. #include <errno.h>
  3. /*
  4. * sigsets are 32-bit longs. if the 2<<(i-1) bit is on,
  5. * the signal #define'd as i in signal.h is inluded.
  6. */
  7. static sigset_t stdsigs = SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGABRT|SIGFPE|SIGKILL|
  8. SIGSEGV|SIGPIPE|SIGALRM|SIGTERM|SIGUSR1|SIGUSR2;
  9. #define BITSIG(s) (2<<(s))
  10. int
  11. sigemptyset(sigset_t *set)
  12. {
  13. *set = 0;
  14. return 0;
  15. }
  16. int
  17. sigfillset(sigset_t *set)
  18. {
  19. *set = stdsigs;
  20. return 0;
  21. }
  22. int
  23. sigaddset(sigset_t *set, int signo)
  24. {
  25. int b;
  26. b = BITSIG(signo);
  27. if(!(b&stdsigs)){
  28. errno = EINVAL;
  29. return -1;
  30. }
  31. *set |= b;
  32. return 0;
  33. }
  34. int
  35. sigdelset(sigset_t *set, int signo)
  36. {
  37. int b;
  38. b = BITSIG(signo);
  39. if(!(b&stdsigs)){
  40. errno = EINVAL;
  41. return -1;
  42. }
  43. *set &= ~b;
  44. return 0;
  45. }
  46. int
  47. sigismember(sigset_t *set, int signo)
  48. {
  49. int b;
  50. b = BITSIG(signo);
  51. if(!(b&stdsigs)){
  52. errno = EINVAL;
  53. return -1;
  54. }
  55. return (b&*set)? 1 : 0;
  56. }