Fix an array-size bug in modmul, and add some tests for it.
[u/mdw/putty] / unix / uxsignal.c
... / ...
CommitLineData
1#include <signal.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5/*
6 * Calling signal() is non-portable, as it varies in meaning
7 * between platforms and depending on feature macros, and has
8 * stupid semantics at least some of the time.
9 *
10 * This function provides the same interface as the libc function,
11 * but provides consistent semantics. It assumes POSIX semantics
12 * for sigaction() (so you might need to do some more work if you
13 * port to something ancient like SunOS 4)
14 */
15void (*putty_signal(int sig, void (*func)(int)))(int) {
16 struct sigaction sa;
17 struct sigaction old;
18
19 sa.sa_handler = func;
20 if(sigemptyset(&sa.sa_mask) < 0)
21 return SIG_ERR;
22 sa.sa_flags = SA_RESTART;
23 if(sigaction(sig, &sa, &old) < 0)
24 return SIG_ERR;
25 return old.sa_handler;
26}
27
28void block_signal(int sig, int block_it)
29{
30 sigset_t ss;
31
32 sigemptyset(&ss);
33 sigaddset(&ss, sig);
34 if(sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) {
35 perror("sigprocmask");
36 exit(1);
37 }
38}
39
40/*
41Local Variables:
42c-basic-offset:4
43comment-column:40
44End:
45*/