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
| | #include <signal.h>
#include <string.h>
int sig2str(int sig, char *str)
{
if (sig <= 0) return -1;
if (sig <= SIGSYS)
return (strcpy(str, __sys_signame[sig]), 0);
if (sig == SIGRTMIN)
return (strcpy(str, "RTMIN"), 0);
if (sig == SIGRTMAX)
return (strcpy(str, "RTMAX"), 0);
if (sig > SIGRTMIN && sig <= SIGRTMAX)
{
strcpy(str, "RTMIN+");
int sigrt = sig-SIGRTMIN;
char *s = str+6;
if (sigrt>=10)
{
*s++ = '0' + sigrt/10;
sigrt %= 10;
}
*s++ = '0' + sigrt;
*s = '\0';
return 0;
}
return -1;
}
|