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