1 /*
2 FUNCTION
3 <<strsignal>>---convert signal number to string
4
5 INDEX
6 strsignal
7
8 SYNOPSIS
9 #include <string.h>
10 char *strsignal(int <[signal]>);
11
12 DESCRIPTION
13 <<strsignal>> converts the signal number <[signal]> into a
14 string. If <[signal]> is not a known signal number, the result
15 will be of the form "Unknown signal NN" where NN is the <[signal]>
16 is a decimal number.
17
18 RETURNS
19 This function returns a pointer to a string. Your application must
20 not modify that string.
21
22 PORTABILITY
23 POSIX.1-2008 C requires <<strsignal>>, but does not specify the strings used
24 for each signal number.
25
26 <<strsignal>> requires no supporting OS subroutines.
27
28 QUICKREF
29 strsignal pure
30 */
31
32 /*
33 * Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
34 *
35 * COPYRIGHT (c) 2010, 2017.
36 * On-Line Applications Research Corporation (OAR).
37 *
38 * Permission to use, copy, modify, and distribute this software for any
39 * purpose without fee is hereby granted, provided that this entire notice
40 * is included in all copies of any software which is or includes a copy
41 * or modification of this software.
42 *
43 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
44 * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
45 * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
46 * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
47 */
48
49 #include <string.h>
50 #include <signal.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53
54 char *
strsignal(int signal)55 strsignal (int signal)
56 {
57 char *buffer;
58 static NEWLIB_THREAD_LOCAL char _signal_buf[24];
59
60 buffer = _signal_buf;
61 #if defined(SIGRTMIN) && defined(SIGRTMAX)
62 if ((signal >= SIGRTMIN) && (signal <= SIGRTMAX)) {
63 sprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
64 return buffer;
65 }
66 #endif
67
68 switch (signal) {
69 #ifdef SIGHUP
70 case SIGHUP:
71 buffer = "Hangup";
72 break;
73 #endif
74 #ifdef SIGINT
75 case SIGINT:
76 buffer = "Interrupt";
77 break;
78 #endif
79 #ifdef SIGQUIT
80 case SIGQUIT:
81 buffer = "Quit";
82 break;
83 #endif
84 #ifdef SIGILL
85 case SIGILL:
86 buffer = "Illegal instruction";
87 break;
88 #endif
89 #ifdef SIGTRAP
90 case SIGTRAP:
91 buffer = "Trace/breakpoint trap";
92 break;
93 #endif
94 #ifdef SIGIOT
95 #if defined(SIGABRT) && (SIGIOT != SIGABRT)
96 case SIGABRT:
97 #endif
98 case SIGIOT:
99 buffer = "IOT trap";
100 break;
101 #endif
102 #ifdef SIGEMT
103 case SIGEMT:
104 buffer = "EMT trap";
105 break;
106 #endif
107 #ifdef SIGFPE
108 case SIGFPE:
109 buffer = "Floating point exception";
110 break;
111 #endif
112 #ifdef SIGKILL
113 case SIGKILL:
114 buffer = "Killed";
115 break;
116 #endif
117 #ifdef SIGBUS
118 case SIGBUS:
119 buffer = "Bus error";
120 break;
121 #endif
122 #ifdef SIGSEGV
123 case SIGSEGV:
124 buffer = "Segmentation fault";
125 break;
126 #endif
127 #ifdef SIGSYS
128 case SIGSYS:
129 buffer = "Bad system call";
130 break;
131 #endif
132 #ifdef SIGPIPE
133 case SIGPIPE:
134 buffer = "Broken pipe";
135 break;
136 #endif
137 #ifdef SIGALRM
138 case SIGALRM:
139 buffer = "Alarm clock";
140 break;
141 #endif
142 #ifdef SIGTERM
143 case SIGTERM:
144 buffer = "Terminated";
145 break;
146 #endif
147 #ifdef SIGURG
148 case SIGURG:
149 buffer = "Urgent I/O condition";
150 break;
151 #endif
152 #ifdef SIGSTOP
153 case SIGSTOP:
154 buffer = "Stopped (signal)";
155 break;
156 #endif
157 #ifdef SIGTSTP
158 case SIGTSTP:
159 buffer = "Stopped";
160 break;
161 #endif
162 #ifdef SIGCONT
163 case SIGCONT:
164 buffer = "Continued";
165 break;
166 #endif
167 #ifdef SIGCHLD
168 #if defined(SIGCLD) && (SIGCHLD != SIGCLD)
169 case SIGCLD:
170 #endif
171 case SIGCHLD:
172 buffer = "Child exited";
173 break;
174 #endif
175 #ifdef SIGTTIN
176 case SIGTTIN:
177 buffer = "Stopped (tty input)";
178 break;
179 #endif
180 #ifdef SIGTTOUT
181 case SIGTTOUT:
182 buffer = "Stopped (tty output)";
183 break;
184 #endif
185 #ifdef SIGIO
186 #if defined(SIGPOLL) && (SIGIO != SIGPOLL)
187 case SIGPOLL:
188 #endif
189 case SIGIO:
190 buffer = "I/O possible";
191 break;
192 #endif
193 #ifdef SIGWINCH
194 case SIGWINCH:
195 buffer = "Window changed";
196 break;
197 #endif
198 #ifdef SIGUSR1
199 case SIGUSR1:
200 buffer = "User defined signal 1";
201 break;
202 #endif
203 #ifdef SIGUSR2
204 case SIGUSR2:
205 buffer = "User defined signal 2";
206 break;
207 #endif
208 #ifdef SIGPWR
209 case SIGPWR:
210 buffer = "Power Failure";
211 break;
212 #endif
213 #ifdef SIGXCPU
214 case SIGXCPU:
215 buffer = "CPU time limit exceeded";
216 break;
217 #endif
218 #ifdef SIGXFSZ
219 case SIGXFSZ:
220 buffer = "File size limit exceeded";
221 break;
222 #endif
223 #ifdef SIGVTALRM
224 case SIGVTALRM :
225 buffer = "Virtual timer expired";
226 break;
227 #endif
228 #ifdef SIGPROF
229 case SIGPROF:
230 buffer = "Profiling timer expired";
231 break;
232 #endif
233 #if defined(SIGLOST) && SIGLOST != SIGPWR
234 case SIGLOST:
235 buffer = "Resource lost";
236 break;
237 #endif
238 default:
239 sprintf (buffer, "Unknown signal %d", signal);
240 break;
241 }
242
243 return buffer;
244 }
245