1#include "locale_impl.h"
2#include <signal.h>
3#include <string.h>
4
5#if (SIGHUP == 1) && (SIGINT == 2) && (SIGQUIT == 3) && (SIGILL == 4) && (SIGTRAP == 5) &&         \
6    (SIGABRT == 6) && (SIGBUS == 7) && (SIGFPE == 8) && (SIGKILL == 9) && (SIGUSR1 == 10) &&       \
7    (SIGSEGV == 11) && (SIGUSR2 == 12) && (SIGPIPE == 13) && (SIGALRM == 14) && (SIGTERM == 15) && \
8    (SIGSTKFLT == 16) && (SIGCHLD == 17) && (SIGCONT == 18) && (SIGSTOP == 19) &&                  \
9    (SIGTSTP == 20) && (SIGTTIN == 21) && (SIGTTOU == 22) && (SIGURG == 23) && (SIGXCPU == 24) &&  \
10    (SIGXFSZ == 25) && (SIGVTALRM == 26) && (SIGPROF == 27) && (SIGWINCH == 28) &&                 \
11    (SIGPOLL == 29) && (SIGPWR == 30) && (SIGSYS == 31)
12
13#define sigmap(x) x
14
15#else
16
17static const char map[] = {[SIGHUP] = 1, [SIGINT] = 2, [SIGQUIT] = 3, [SIGILL] = 4,
18                           [SIGTRAP] = 5, [SIGABRT] = 6, [SIGBUS] = 7, [SIGFPE] = 8,
19                           [SIGKILL] = 9, [SIGUSR1] = 10, [SIGSEGV] = 11, [SIGUSR2] = 12,
20                           [SIGPIPE] = 13, [SIGALRM] = 14, [SIGTERM] = 15, [SIGSTKFLT] = 16,
21                           [SIGCHLD] = 17, [SIGCONT] = 18, [SIGSTOP] = 19, [SIGTSTP] = 20,
22                           [SIGTTIN] = 21, [SIGTTOU] = 22, [SIGURG] = 23, [SIGXCPU] = 24,
23                           [SIGXFSZ] = 25, [SIGVTALRM] = 26, [SIGPROF] = 27, [SIGWINCH] = 28,
24                           [SIGPOLL] = 29, [SIGPWR] = 30, [SIGSYS] = 31};
25
26#define sigmap(x) ((x) >= sizeof map ? (x) : map[(x)])
27
28#endif
29
30static const char strings[] = "Unknown signal\0"
31                              "Hangup\0"
32                              "Interrupt\0"
33                              "Quit\0"
34                              "Illegal instruction\0"
35                              "Trace/breakpoint trap\0"
36                              "Aborted\0"
37                              "Bus error\0"
38                              "Arithmetic exception\0"
39                              "Killed\0"
40                              "User defined signal 1\0"
41                              "Segmentation fault\0"
42                              "User defined signal 2\0"
43                              "Broken pipe\0"
44                              "Alarm clock\0"
45                              "Terminated\0"
46                              "Stack fault\0"
47                              "Child process status\0"
48                              "Continued\0"
49                              "Stopped (signal)\0"
50                              "Stopped\0"
51                              "Stopped (tty input)\0"
52                              "Stopped (tty output)\0"
53                              "Urgent I/O condition\0"
54                              "CPU time limit exceeded\0"
55                              "File size limit exceeded\0"
56                              "Virtual timer expired\0"
57                              "Profiling timer expired\0"
58                              "Window changed\0"
59                              "I/O possible\0"
60                              "Power failure\0"
61                              "Bad system call\0"
62                              "RT32"
63                              "\0RT33\0RT34\0RT35\0RT36\0RT37\0RT38\0RT39\0RT40"
64                              "\0RT41\0RT42\0RT43\0RT44\0RT45\0RT46\0RT47\0RT48"
65                              "\0RT49\0RT50\0RT51\0RT52\0RT53\0RT54\0RT55\0RT56"
66                              "\0RT57\0RT58\0RT59\0RT60\0RT61\0RT62\0RT63\0RT64"
67#if _NSIG > 65
68                              "\0RT65\0RT66\0RT67\0RT68\0RT69\0RT70\0RT71\0RT72"
69                              "\0RT73\0RT74\0RT75\0RT76\0RT77\0RT78\0RT79\0RT80"
70                              "\0RT81\0RT82\0RT83\0RT84\0RT85\0RT86\0RT87\0RT88"
71                              "\0RT89\0RT90\0RT91\0RT92\0RT93\0RT94\0RT95\0RT96"
72                              "\0RT97\0RT98\0RT99\0RT100\0RT101\0RT102\0RT103\0RT104"
73                              "\0RT105\0RT106\0RT107\0RT108\0RT109\0RT110\0RT111\0RT112"
74                              "\0RT113\0RT114\0RT115\0RT116\0RT117\0RT118\0RT119\0RT120"
75                              "\0RT121\0RT122\0RT123\0RT124\0RT125\0RT126\0RT127\0RT128"
76#endif
77                              "";
78
79char* strsignal(int signum) {
80    const char* s = strings;
81
82    signum = sigmap(signum);
83    if (signum - 1U >= _NSIG - 1)
84        signum = 0;
85
86    for (; signum--; s++)
87        for (; *s; s++)
88            ;
89
90    return (char*)LCTRANS_CUR(s);
91}
92