summaryrefslogtreecommitdiff
path: root/lib/compat/strsignal.c
blob: c4028886a5abe9276a321c1b73537124bcb61b1b (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * libcompat - system compatibility library
 *
 * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <config.h>

#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <gettext.h>

#include "compat.h"

#define _(str) gettext(str)

#if !HAVE_DECL_SYS_SIGLIST
# ifdef __sun__
/* sys/iso/signal_iso.h */
const char *const sys_siglist[] = {
	NULL         , /* 0 */
	"SIGHUP"     , /* 1 */
	"SIGINT"     , /* 2 */
	"SIGQUIT"    , /* 3 */
	"SIGILL"     , /* 4 */
	"SIGTRAP"    , /* 5 */
	"SIGIOT"     , /* 6 */
	"SIGABRT"    , /* 6 */
	"SIGEMT"     , /* 7 */
	"SIGFPE"     , /* 8 */
	"SIGKILL"    , /* 9 */
	"SIGBUS"     , /* 10 */
	"SIGSEGV"    , /* 11 */
	"SIGSYS"     , /* 12 */
	"SIGPIPE"    , /* 13 */
	"SIGALRM"    , /* 14 */
	"SIGTERM"    , /* 15 */
	"SIGUSR1"    , /* 16 */
	"SIGUSR2"    , /* 17 */
	"SIGCLD"     , /* 18 */
	"SIGCHLD"    , /* 18 */
	"SIGPWR"     , /* 19 */
	"SIGWINCH"   , /* 20 */
	"SIGURG"     , /* 21 */
	"SIGPOLL"    , /* 22 */
	"SIGSTOP"    , /* 23 */
	"SIGTSTP"    , /* 24 */
	"SIGCONT"    , /* 25 */
	"SIGTTIN"    , /* 26 */
	"SIGTTOU"    , /* 27 */
	"SIGVTALRM"  , /* 28 */
	"SIGPROF"    , /* 29 */
	"SIGXCPU"    , /* 30 */
	"SIGXFSZ"    , /* 31 */
	"SIGWAITING" , /* 32 */
	"SIGLWP"     , /* 33 */
	"SIGFREEZE"  , /* 34 */
	"SIGTHAW"    , /* 35 */
	"SIGCANCEL"  , /* 36 */
	"SIGLOST"    , /* 37 */
	"SIGXRES"    , /* 38 */
	"SIGJVM1"    , /* 39 */
	"SIGJVM2"    , /* 40 */
	"SIGINFO"      /* 41 */
};
# else
const char *const sys_siglist[] = {
	NULL,		/* 0 */
	"SIGHUP",	/* 1 */
	"SIGINT",	/* 2 */
	"SIGQUIT",	/* 3 */
	"SIGILL",	/* 4 */
	"SIGTRAP",	/* 5 */
	"SIGABRT",	/* 6 */
	"SIGEMT",	/* 7 */
	"SIGFPE",	/* 8 */
	"SIGKILL",	/* 9 */
	"SIGUSR1",	/* 10 */
	"SIGSEGV",	/* 11 */
	"SIGUSR2",	/* 12 */
	"SIGPIPE",	/* 13 */
	"SIGALRM",	/* 14 */
	"SIGTERM",	/* 15 */
	"SIGSTKFLT",	/* 16 */
	"SIGCHLD",	/* 17 */
	"SIGCONT",	/* 18 */
	"SIGSTOP",	/* 19 */
	"SIGTSTP",	/* 20 */
	"SIGTTIN",	/* 21 */
	"SIGTTOU",	/* 22 */
};
# endif
#else
/* XXX sizeof empty array does not work */
extern const char *const sys_siglist[];
#endif

const char *
strsignal(int s)
{
	static char buf[100];

	if (s > 0 && s < (int)(sizeof(sys_siglist) / sizeof(sys_siglist[0])))
		return sys_siglist[s];

	sprintf(buf, _("Unknown signal %d"), s);

	return buf;
}