signame.c
1/* $OpenBSD: signame.c,v 1.5 2009/11/27 19:47:45 guenther Exp $ */
2/*
3 * Copyright (c) 1983 Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include "pconfig.h"
32
33#ifndef HAVE_SIGNAME
34
35#include <signal.h>
36#include <unistd.h>
37
38static const struct {
39 int sig;
40 const char *name;
41} signame[] = {
42 { 0, "Signal 0" },
43#ifdef SIGHUP
44 { SIGHUP, "HUP" },
45#endif
46#ifdef SIGINT
47 { SIGINT, "INT" },
48#endif
49#ifdef SIGQUIT
50 { SIGQUIT, "QUIT" },
51#endif
52#ifdef SIGILL
53 { SIGILL, "ILL" },
54#endif
55#ifdef SIGTRAP
56 { SIGTRAP, "TRAP" },
57#endif
58#ifdef SIGABRT
59 { SIGABRT, "ABRT" },
60#endif
61#ifdef SIGEMT
62 { SIGEMT, "EMT" },
63#endif
64#ifdef SIGFPE
65 { SIGFPE, "FPE" },
66#endif
67#ifdef SIGKILL
68 { SIGKILL, "KILL" },
69#endif
70#ifdef SIGBUS
71 { SIGBUS, "BUS" },
72#endif
73#ifdef SIGSEGV
74 { SIGSEGV, "SEGV" },
75#endif
76#ifdef SIGSYS
77 { SIGSYS, "SYS" },
78#endif
79#ifdef SIGPIPE
80 { SIGPIPE, "PIPE" },
81#endif
82#ifdef SIGALRM
83 { SIGALRM, "ALRM" },
84#endif
85#ifdef SIGTERM
86 { SIGTERM, "TERM" },
87#endif
88#ifdef SIGURG
89 { SIGURG, "URG" },
90#endif
91#ifdef SIGSTOP
92 { SIGSTOP, "STOP" },
93#endif
94#ifdef SIGTSTP
95 { SIGTSTP, "TSTP" },
96#endif
97#ifdef SIGCONT
98 { SIGCONT, "CONT" },
99#endif
100#ifdef SIGCHLD
101 { SIGCHLD, "CHLD" },
102#endif
103#ifdef SIGTTIN
104 { SIGTTIN, "TTIN" },
105#endif
106#ifdef SIGTTOU
107 { SIGTTOU, "TTOU" },
108#endif
109#ifdef SIGIO
110 { SIGIO, "IO" },
111#endif
112#ifdef SIGXCPU
113 { SIGXCPU, "XCPU" },
114#endif
115#ifdef SIGXFSZ
116 { SIGXFSZ, "XFSZ" },
117#endif
118#ifdef SIGVTALRM
119 { SIGVTALRM, "VTALRM" },
120#endif
121#ifdef SIGPROF
122 { SIGPROF, "PROF" },
123#endif
124#ifdef SIGWINCH
125 { SIGWINCH, "WINCH" },
126#endif
127#ifdef SIGINFO
128 { SIGINFO, "INFO" },
129#endif
130#ifdef SIGUSR1
131 { SIGUSR1, "USR1" },
132#endif
133#ifdef SIGUSR2
134 { SIGUSR2, "USR2" },
135#endif
136#ifdef SIGPWR
137 { SIGPWR, "PWR" },
138#endif
139#ifdef SIGSTKFLT
140 { SIGSTKFLT, "STKFLT" },
141#endif
142};
143
144const char *
145oksh_sig2str(int sig)
146{
147 int i;
148
149 for (i = 0; i < sizeof(signame) / sizeof(*signame); i++) {
150 if (signame[i].sig == sig)
151 return signame[i].name;
152 }
153
154 return "UNKNOWN";
155}
156
157#endif /* !HAVE_SIGNAME */