Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / strsignal.c
blob89d39fe3c2f0b7e18ba0b6594c3af895711bb71f
1 /*
2 FUNCTION
3 <<strsignal>>---convert signal number to string
5 INDEX
6 strsignal
8 SYNOPSIS
9 #include <string.h>
10 char *strsignal(int <[signal]>);
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.
18 RETURNS
19 This function returns a pointer to a string. Your application must
20 not modify that string.
22 PORTABILITY
23 POSIX.1-2008 C requires <<strsignal>>, but does not specify the strings used
24 for each signal number.
26 <<strsignal>> requires no supporting OS subroutines.
28 QUICKREF
29 strsignal pure
33 * Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
35 * COPYRIGHT (c) 2010, 2017.
36 * On-Line Applications Research Corporation (OAR).
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.
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.
49 #include <string.h>
50 #include <signal.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <reent.h>
55 #ifdef _REENT_THREAD_LOCAL
56 _Thread_local char _tls_signal_buf[_REENT_SIGNAL_SIZE];
57 #endif
59 char *
60 strsignal (int signal)
62 char *buffer;
63 struct _reent *ptr;
65 ptr = _REENT;
67 _REENT_CHECK_SIGNAL_BUF(ptr);
68 buffer = _REENT_SIGNAL_BUF(ptr);
70 #if defined(SIGRTMIN) && defined(SIGRTMAX)
71 if ((signal >= SIGRTMIN) && (signal <= SIGRTMAX)) {
72 siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
73 return buffer;
75 #endif
77 switch (signal) {
78 #ifdef SIGHUP
79 case SIGHUP:
80 buffer = "Hangup";
81 break;
82 #endif
83 #ifdef SIGINT
84 case SIGINT:
85 buffer = "Interrupt";
86 break;
87 #endif
88 #ifdef SIGQUIT
89 case SIGQUIT:
90 buffer = "Quit";
91 break;
92 #endif
93 #ifdef SIGILL
94 case SIGILL:
95 buffer = "Illegal instruction";
96 break;
97 #endif
98 #ifdef SIGTRAP
99 case SIGTRAP:
100 buffer = "Trace/breakpoint trap";
101 break;
102 #endif
103 #ifdef SIGIOT
104 #if defined(SIGABRT) && (SIGIOT != SIGABRT)
105 case SIGABRT:
106 #endif
107 case SIGIOT:
108 buffer = "IOT trap";
109 break;
110 #endif
111 #ifdef SIGEMT
112 case SIGEMT:
113 buffer = "EMT trap";
114 break;
115 #endif
116 #ifdef SIGFPE
117 case SIGFPE:
118 buffer = "Floating point exception";
119 break;
120 #endif
121 #ifdef SIGKILL
122 case SIGKILL:
123 buffer = "Killed";
124 break;
125 #endif
126 #ifdef SIGBUS
127 case SIGBUS:
128 buffer = "Bus error";
129 break;
130 #endif
131 #ifdef SIGSEGV
132 case SIGSEGV:
133 buffer = "Segmentation fault";
134 break;
135 #endif
136 #ifdef SIGSYS
137 case SIGSYS:
138 buffer = "Bad system call";
139 break;
140 #endif
141 #ifdef SIGPIPE
142 case SIGPIPE:
143 buffer = "Broken pipe";
144 break;
145 #endif
146 #ifdef SIGALRM
147 case SIGALRM:
148 buffer = "Alarm clock";
149 break;
150 #endif
151 #ifdef SIGTERM
152 case SIGTERM:
153 buffer = "Terminated";
154 break;
155 #endif
156 #ifdef SIGURG
157 case SIGURG:
158 buffer = "Urgent I/O condition";
159 break;
160 #endif
161 #ifdef SIGSTOP
162 case SIGSTOP:
163 buffer = "Stopped (signal)";
164 break;
165 #endif
166 #ifdef SIGTSTP
167 case SIGTSTP:
168 buffer = "Stopped";
169 break;
170 #endif
171 #ifdef SIGCONT
172 case SIGCONT:
173 buffer = "Continued";
174 break;
175 #endif
176 #ifdef SIGCHLD
177 #if defined(SIGCLD) && (SIGCHLD != SIGCLD)
178 case SIGCLD:
179 #endif
180 case SIGCHLD:
181 buffer = "Child exited";
182 break;
183 #endif
184 #ifdef SIGTTIN
185 case SIGTTIN:
186 buffer = "Stopped (tty input)";
187 break;
188 #endif
189 #ifdef SIGTTOUT
190 case SIGTTOUT:
191 buffer = "Stopped (tty output)";
192 break;
193 #endif
194 #ifdef SIGIO
195 #if defined(SIGPOLL) && (SIGIO != SIGPOLL)
196 case SIGPOLL:
197 #endif
198 case SIGIO:
199 buffer = "I/O possible";
200 break;
201 #endif
202 #ifdef SIGWINCH
203 case SIGWINCH:
204 buffer = "Window changed";
205 break;
206 #endif
207 #ifdef SIGUSR1
208 case SIGUSR1:
209 buffer = "User defined signal 1";
210 break;
211 #endif
212 #ifdef SIGUSR2
213 case SIGUSR2:
214 buffer = "User defined signal 2";
215 break;
216 #endif
217 #ifdef SIGPWR
218 case SIGPWR:
219 buffer = "Power Failure";
220 break;
221 #endif
222 #ifdef SIGXCPU
223 case SIGXCPU:
224 buffer = "CPU time limit exceeded";
225 break;
226 #endif
227 #ifdef SIGXFSZ
228 case SIGXFSZ:
229 buffer = "File size limit exceeded";
230 break;
231 #endif
232 #ifdef SIGVTALRM
233 case SIGVTALRM :
234 buffer = "Virtual timer expired";
235 break;
236 #endif
237 #ifdef SIGPROF
238 case SIGPROF:
239 buffer = "Profiling timer expired";
240 break;
241 #endif
242 #if defined(SIGLOST) && SIGLOST != SIGPWR
243 case SIGLOST:
244 buffer = "Resource lost";
245 break;
246 #endif
247 default:
248 siprintf (buffer, "Unknown signal %d", signal);
249 break;
252 return buffer;