chiark / gitweb /
lib/dpkg/tarfn.c: Kludge `tar_header_decode' to handle spurious `errno'.
[dpkg] / lib / compat / strsignal.c
1 /*
2  * libcompat - system compatibility library
3  *
4  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19
20 #include <config.h>
21
22 #include <signal.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <gettext.h>
26
27 #include "compat.h"
28
29 #define _(str) gettext(str)
30
31 #if !HAVE_DECL_SYS_SIGLIST
32 const char *const sys_siglist[] = {
33         NULL,           /* 0 */
34         "SIGHUP",       /* 1 */
35         "SIGINT",       /* 2 */
36         "SIGQUIT",      /* 3 */
37         "SIGILL",       /* 4 */
38         "SIGTRAP",      /* 5 */
39         "SIGABRT",      /* 6 */
40         "SIGEMT",       /* 7 */
41         "SIGFPE",       /* 8 */
42         "SIGKILL",      /* 9 */
43         "SIGUSR1",      /* 10 */
44         "SIGSEGV",      /* 11 */
45         "SIGUSR2",      /* 12 */
46         "SIGPIPE",      /* 13 */
47         "SIGALRM",      /* 14 */
48         "SIGTERM",      /* 15 */
49         "SIGSTKFLT",    /* 16 */
50         "SIGCHLD",      /* 17 */
51         "SIGCONT",      /* 18 */
52         "SIGSTOP",      /* 19 */
53         "SIGTSTP",      /* 20 */
54         "SIGTTIN",      /* 21 */
55         "SIGTTOU",      /* 22 */
56 };
57 # define COMPAT_NSIGLIST (int)(sizeof(sys_siglist) / sizeof(sys_siglist[0]))
58 #else
59 # ifndef NSIG
60 #  define NSIG 32
61 # endif
62 # define COMPAT_NSIGLIST NSIG
63 #endif
64
65 const char *
66 strsignal(int s)
67 {
68         static char buf[100];
69
70         if (s > 0 && s < COMPAT_NSIGLIST)
71                 return sys_siglist[s];
72
73         sprintf(buf, _("Unknown signal %d"), s);
74
75         return buf;
76 }