bsd_sig.c 693 B

12345678910111213141516171819202122232425262728293031323334
  1. #define __USE_BSD_SIGNAL
  2. #include <signal.h>
  3. #undef signal
  4. /* The `sig' bit is set if the interrupt on it
  5. * is enabled via siginterrupt (). */
  6. extern sigset_t _sigintr;
  7. __sighandler_t
  8. __bsd_signal (int sig, __sighandler_t handler)
  9. {
  10. int ret;
  11. struct sigaction action, oaction;
  12. action.sa_handler = handler;
  13. __sigemptyset (&action.sa_mask);
  14. if (!__sigismember (&_sigintr, sig)) {
  15. #ifdef SA_RESTART
  16. action.sa_flags = SA_RESTART;
  17. #else
  18. action.sa_flags = 0;
  19. #endif
  20. }
  21. else {
  22. #ifdef SA_INTERRUPT
  23. action.sa_flags = SA_INTERRUPT;
  24. #else
  25. action.sa_flags = 0;
  26. #endif
  27. }
  28. ret = sigaction (sig, &action, &oaction);
  29. return (ret == -1) ? SIG_ERR : oaction.sa_handler;
  30. }