X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxsignal.c;fp=unix%2Fuxsignal.c;h=e21e0e8052d66216eca88923650152fb4d31bd66;hb=c64ad3bb0ceb7d453f3ee6e6f6a1727a6a8da9cc;hp=0000000000000000000000000000000000000000;hpb=95cd4797691e46e7cd6646a20226d306f734e6d9;p=PuTTY.git diff --git a/unix/uxsignal.c b/unix/uxsignal.c new file mode 100644 index 00000000..e21e0e80 --- /dev/null +++ b/unix/uxsignal.c @@ -0,0 +1,45 @@ +#include +#include +#include + +/* + * Calling signal() is non-portable, as it varies in meaning + * between platforms and depending on feature macros, and has + * stupid semantics at least some of the time. + * + * This function provides the same interface as the libc function, + * but provides consistent semantics. It assumes POSIX semantics + * for sigaction() (so you might need to do some more work if you + * port to something ancient like SunOS 4) + */ +void (*putty_signal(int sig, void (*func)(int)))(int) { + struct sigaction sa; + struct sigaction old; + + sa.sa_handler = func; + if(sigemptyset(&sa.sa_mask) < 0) + return SIG_ERR; + sa.sa_flags = SA_RESTART; + if(sigaction(sig, &sa, &old) < 0) + return SIG_ERR; + return old.sa_handler; +} + +void block_signal(int sig, int block_it) +{ + sigset_t ss; + + sigemptyset(&ss); + sigaddset(&ss, sig); + if(sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) { + perror("sigprocmask"); + exit(1); + } +} + +/* +Local Variables: +c-basic-offset:4 +comment-column:40 +End: +*/