1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
| | #include <signal.h>
#include <stdio.h>
#include <string.h>
int sig2str(int signum, char *str)
{
const char *name = NULL;
switch(signum)
{
case SIGHUP: name = "HUP"; break;
case SIGINT: name = "INT"; break;
case SIGQUIT: name = "QUIT"; break;
case SIGILL: name = "ILL"; break;
case SIGTRAP: name = "TRAP"; break;
case SIGABRT: name = "ABRT"; break;
case SIGBUS: name = "BUS"; break;
case SIGFPE: name = "FPE"; break;
case SIGKILL: name = "KILL"; break;
case SIGUSR1: name = "USR1"; break;
case SIGSEGV: name = "SEGV"; break;
case SIGUSR2: name = "USR2"; break;
case SIGPIPE: name = "PIPE"; break;
case SIGALRM: name = "ALRM"; break;
case SIGTERM: name = "TERM"; break;
case SIGSTKFLT: name = "STKFLT"; break;
case SIGCHLD: name = "CHLD"; break;
case SIGCONT: name = "CONT"; break;
case SIGSTOP: name = "STOP"; break;
case SIGTSTP: name = "TSTP"; break;
case SIGTTIN: name = "TTIN"; break;
case SIGTTOU: name = "TTOU"; break;
case SIGURG: name = "URG"; break;
case SIGXCPU: name = "XCPU"; break;
case SIGXFSZ: name = "XFSZ"; break;
case SIGVTALRM: name = "VTALRM"; break;
case SIGPROF: name = "PROF"; break;
case SIGWINCH: name = "WINCH"; break;
case SIGIO: name = "IO"; break;
case SIGPWR: name = "PWR"; break;
case SIGSYS: name = "SYS"; break;
}
// macros to functions can't be in switch-case
if(signum == SIGRTMIN) name = "RTMIN";
if(signum == SIGRTMAX) name = "RTMAX";
if(SIGRTMIN+1 <= signum && signum <= SIGRTMAX-1)
{
if(snprintf(str, SIG2STR_MAX, "RTMIN+%i", signum-SIGRTMIN) < 0) return -1;
return 0;
}
if(name == NULL) return -1;
strcpy(str, name);
return 0;
}
|