signal.c 815 B

1234567891011121314151617181920212223242526272829303132
  1. #include <signal.h>
  2. /*
  3. * Calling signal() is a non-portable, as it varies in meaning between
  4. * platforms and depending on feature macros, and has stupid semantics
  5. * at least some of the time.
  6. *
  7. * This function provides the same interface as the libc function, but
  8. * provides consistent semantics. It assumes POSIX semantics for
  9. * sigaction() (so you might need to do some more work if you port to
  10. * something ancient like SunOS 4)
  11. */
  12. void (*putty_signal(int sig, void (*func)(int)))(int) {
  13. struct sigaction sa;
  14. struct sigaction old;
  15. sa.sa_handler = func;
  16. if(sigemptyset(&sa.sa_mask) < 0)
  17. return SIG_ERR;
  18. sa.sa_flags = SA_RESTART;
  19. if(sigaction(sig, &sa, &old) < 0)
  20. return SIG_ERR;
  21. return old.sa_handler;
  22. }
  23. /*
  24. Local Variables:
  25. c-basic-offset:4
  26. comment-column:40
  27. End:
  28. */