Fix for the problem that SDL applications exited
[AROS-Contrib.git] / gnu / make / signame.c
blob096444260c6566983298d41ca7e16a70e9605b0f
1 /* Convert between signal names and numbers.
2 Copyright (C) 1990,92,93,95,96,99, 2002 Free Software Foundation, Inc.
3 This file was part of the GNU C Library, but is now part of GNU make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include "make.h"
22 /* If the system provides strsignal, we don't need it. */
24 #if !defined(HAVE_STRSIGNAL)
26 /* If the system provides sys_siglist, we'll use that.
27 Otherwise create our own.
30 #if !defined(SYS_SIGLIST_DECLARED)
32 /* Some systems do not define NSIG in <signal.h>. */
33 #ifndef NSIG
34 #ifdef _NSIG
35 #define NSIG _NSIG
36 #else
37 #define NSIG 32
38 #endif
39 #endif
41 /* There is too much variation in Sys V signal numbers and names, so
42 we must initialize them at runtime. */
44 static const char *undoc;
46 /* orig andy static char *sys_siglist[NSIG]; */
47 static const char * sys_siglist[NSIG];
50 /* Table of abbreviations for signals. Note: A given number can
51 appear more than once with different abbreviations. */
52 #define SIG_TABLE_SIZE (NSIG*2)
54 typedef struct
56 int number;
57 const char *abbrev;
58 } num_abbrev;
60 static num_abbrev sig_table[SIG_TABLE_SIZE];
62 /* Number of elements of sig_table used. */
63 static int sig_table_nelts = 0;
65 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
67 static void
68 init_sig (int number, const char *abbrev, const char *name)
70 /* If this value is ever greater than NSIG it seems like it'd be a bug in
71 the system headers, but... better safe than sorry. We know, for
72 example, that this isn't always true on VMS. */
74 if (number >= 0 && number < NSIG)
75 sys_siglist[number] = name;
77 if (sig_table_nelts < SIG_TABLE_SIZE)
79 sig_table[sig_table_nelts].number = number;
80 sig_table[sig_table_nelts++].abbrev = abbrev;
84 static int
85 signame_init (void)
87 int i;
89 undoc = xstrdup (_("unknown signal"));
91 /* Initialize signal names. */
92 for (i = 0; i < NSIG; i++)
93 sys_siglist[i] = undoc;
95 /* Initialize signal names. */
96 #if defined (SIGHUP)
97 init_sig (SIGHUP, "HUP", _("Hangup"));
98 #endif
99 #if defined (SIGINT)
100 init_sig (SIGINT, "INT", _("Interrupt"));
101 #endif
102 #if defined (SIGQUIT)
103 init_sig (SIGQUIT, "QUIT", _("Quit"));
104 #endif
105 #if defined (SIGILL)
106 init_sig (SIGILL, "ILL", _("Illegal Instruction"));
107 #endif
108 #if defined (SIGTRAP)
109 init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
110 #endif
111 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
112 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
113 #if defined (SIGABRT)
114 init_sig (SIGABRT, "ABRT", _("Aborted"));
115 #endif
116 #if defined (SIGIOT)
117 init_sig (SIGIOT, "IOT", _("IOT trap"));
118 #endif
119 #if defined (SIGEMT)
120 init_sig (SIGEMT, "EMT", _("EMT trap"));
121 #endif
122 #if defined (SIGFPE)
123 init_sig (SIGFPE, "FPE", _("Floating point exception"));
124 #endif
125 #if defined (SIGKILL)
126 init_sig (SIGKILL, "KILL", _("Killed"));
127 #endif
128 #if defined (SIGBUS)
129 init_sig (SIGBUS, "BUS", _("Bus error"));
130 #endif
131 #if defined (SIGSEGV)
132 init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
133 #endif
134 #if defined (SIGSYS)
135 init_sig (SIGSYS, "SYS", _("Bad system call"));
136 #endif
137 #if defined (SIGPIPE)
138 init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
139 #endif
140 #if defined (SIGALRM)
141 init_sig (SIGALRM, "ALRM", _("Alarm clock"));
142 #endif
143 #if defined (SIGTERM)
144 init_sig (SIGTERM, "TERM", _("Terminated"));
145 #endif
146 #if defined (SIGUSR1)
147 init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
148 #endif
149 #if defined (SIGUSR2)
150 init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
151 #endif
152 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
153 is what is in POSIX.1. */
154 #if defined (SIGCHLD)
155 init_sig (SIGCHLD, "CHLD", _("Child exited"));
156 #endif
157 #if defined (SIGCLD)
158 init_sig (SIGCLD, "CLD", _("Child exited"));
159 #endif
160 #if defined (SIGPWR)
161 init_sig (SIGPWR, "PWR", _("Power failure"));
162 #endif
163 #if defined (SIGTSTP)
164 init_sig (SIGTSTP, "TSTP", _("Stopped"));
165 #endif
166 #if defined (SIGTTIN)
167 init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
168 #endif
169 #if defined (SIGTTOU)
170 init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
171 #endif
172 #if defined (SIGSTOP)
173 init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
174 #endif
175 #if defined (SIGXCPU)
176 init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
177 #endif
178 #if defined (SIGXFSZ)
179 init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
180 #endif
181 #if defined (SIGVTALRM)
182 init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
183 #endif
184 #if defined (SIGPROF)
185 init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
186 #endif
187 #if defined (SIGWINCH)
188 /* "Window size changed" might be more accurate, but even if that
189 is all that it means now, perhaps in the future it will be
190 extended to cover other kinds of window changes. */
191 init_sig (SIGWINCH, "WINCH", _("Window changed"));
192 #endif
193 #if defined (SIGCONT)
194 init_sig (SIGCONT, "CONT", _("Continued"));
195 #endif
196 #if defined (SIGURG)
197 init_sig (SIGURG, "URG", _("Urgent I/O condition"));
198 #endif
199 #if defined (SIGIO)
200 /* "I/O pending" has also been suggested. A disadvantage is
201 that signal only happens when the process has
202 asked for it, not everytime I/O is pending. Another disadvantage
203 is the confusion from giving it a different name than under Unix. */
204 init_sig (SIGIO, "IO", _("I/O possible"));
205 #endif
206 #if defined (SIGWIND)
207 init_sig (SIGWIND, "WIND", _("SIGWIND"));
208 #endif
209 #if defined (SIGPHONE)
210 init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
211 #endif
212 #if defined (SIGPOLL)
213 init_sig (SIGPOLL, "POLL", _("I/O possible"));
214 #endif
215 #if defined (SIGLOST)
216 init_sig (SIGLOST, "LOST", _("Resource lost"));
217 #endif
218 #if defined (SIGDANGER)
219 init_sig (SIGDANGER, "DANGER", _("Danger signal"));
220 #endif
221 #if defined (SIGINFO)
222 init_sig (SIGINFO, "INFO", _("Information request"));
223 #endif
224 #if defined (SIGNOFP)
225 init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
226 #endif
228 return 1;
231 #endif /* SYS_SIGLIST_DECLARED */
234 char *
235 strsignal (int signal)
237 static char buf[] = "Signal 12345678901234567890";
239 #if !defined(SYS_SIGLIST_DECLARED)
240 static char sig_initted = 0;
242 if (!sig_initted)
243 sig_initted = signame_init ();
244 #endif
246 if (signal > 0 || signal < NSIG)
247 return (char *) sys_siglist[signal];
249 sprintf (buf, "Signal %d", signal);
250 return buf;
253 #endif /* HAVE_STRSIGNAL */