Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / strsig.cc
blobb92781c78c8eb96d55608508b185f1092cdcaecb
1 /* strsig.cc
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #include "winsup.h"
10 #include <cygtls.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <sys/uio.h>
15 struct sigdesc
17 int n;
18 const char *name;
19 const char *str;
22 #define __signals \
23 _s(SIGHUP, "Hangup"), /* 1 */ \
24 _s(SIGINT, "Interrupt"), /* 2 */ \
25 _s(SIGQUIT, "Quit"), /* 3 */ \
26 _s(SIGILL, "Illegal instruction"), /* 4 */ \
27 _s(SIGTRAP, "Trace/breakpoint trap"), /* 5 */ \
28 _s2(SIGABRT, "Aborted", /* 6 */ \
29 SIGIOT, "Aborted"), \
30 _s(SIGEMT, "EMT instruction"), /* 7 */ \
31 _s(SIGFPE, "Floating point exception"), /* 8 */ \
32 _s(SIGKILL, "Killed"), /* 9 */ \
33 _s(SIGBUS, "Bus error"), /* 10 */ \
34 _s(SIGSEGV, "Segmentation fault"), /* 11 */ \
35 _s(SIGSYS, "Bad system call"), /* 12 */ \
36 _s(SIGPIPE, "Broken pipe"), /* 13 */ \
37 _s(SIGALRM, "Alarm clock"), /* 14 */ \
38 _s(SIGTERM, "Terminated"), /* 15 */ \
39 _s(SIGURG, "Urgent I/O condition"), /* 16 */ \
40 _s(SIGSTOP, "Stopped (signal)"), /* 17 */ \
41 _s(SIGTSTP, "Stopped"), /* 18 */ \
42 _s(SIGCONT, "Continued"), /* 19 */ \
43 _s2(SIGCHLD, "Child exited", /* 20 */ \
44 SIGCLD, "Child exited"), \
45 _s(SIGTTIN, "Stopped (tty input)"), /* 21 */ \
46 _s(SIGTTOU, "Stopped (tty output)"), /* 22 */ \
47 _s2(SIGIO, "I/O possible", /* 23 */ \
48 SIGPOLL, "I/O possible"), \
49 _s(SIGXCPU, "CPU time limit exceeded"), /* 24 */ \
50 _s(SIGXFSZ, "File size limit exceeded"), /* 25 */ \
51 _s(SIGVTALRM, "Virtual timer expired"), /* 26 */ \
52 _s(SIGPROF, "Profiling timer expired"), /* 27 */ \
53 _s(SIGWINCH, "Window changed"), /* 28 */ \
54 _s2(SIGPWR, "Power failure", /* 29 */ \
55 SIGLOST, "Resource lost"), \
56 _s(SIGUSR1, "User defined signal 1"), /* 30 */ \
57 _s(SIGUSR2, "User defined signal 2"), /* 31 */ \
58 _s(SIGRTMIN, "Real-time signal 0"), /* 32 */ \
59 _s(SIGRTMIN+1, "Real-time signal 1"), /* 33 */ \
60 _s(SIGRTMIN+2, "Real-time signal 2"), /* 34 */ \
61 _s(SIGRTMIN+3, "Real-time signal 3"), /* 35 */ \
62 _s(SIGRTMIN+4, "Real-time signal 4"), /* 36 */ \
63 _s(SIGRTMIN+5, "Real-time signal 5"), /* 37 */ \
64 _s(SIGRTMIN+6, "Real-time signal 6"), /* 38 */ \
65 _s(SIGRTMIN+7, "Real-time signal 7"), /* 39 */ \
66 _s(SIGRTMIN+8, "Real-time signal 8"), /* 40 */ \
67 _s(SIGRTMIN+9, "Real-time signal 9"), /* 41 */ \
68 _s(SIGRTMIN+10, "Real-time signal 10"), /* 42 */ \
69 _s(SIGRTMIN+11, "Real-time signal 11"), /* 43 */ \
70 _s(SIGRTMIN+12, "Real-time signal 12"), /* 44 */ \
71 _s(SIGRTMIN+13, "Real-time signal 13"), /* 45 */ \
72 _s(SIGRTMIN+14, "Real-time signal 14"), /* 46 */ \
73 _s(SIGRTMIN+15, "Real-time signal 15"), /* 47 */ \
74 _s(SIGRTMIN+16, "Real-time signal 16"), /* 48 */ \
75 _s(SIGRTMIN+17, "Real-time signal 17"), /* 49 */ \
76 _s(SIGRTMIN+18, "Real-time signal 18"), /* 50 */ \
77 _s(SIGRTMIN+19, "Real-time signal 19"), /* 51 */ \
78 _s(SIGRTMIN+20, "Real-time signal 20"), /* 52 */ \
79 _s(SIGRTMIN+21, "Real-time signal 21"), /* 53 */ \
80 _s(SIGRTMIN+22, "Real-time signal 22"), /* 54 */ \
81 _s(SIGRTMIN+23, "Real-time signal 23"), /* 55 */ \
82 _s(SIGRTMIN+24, "Real-time signal 24"), /* 56 */ \
83 _s(SIGRTMIN+25, "Real-time signal 25"), /* 57 */ \
84 _s(SIGRTMIN+26, "Real-time signal 26"), /* 58 */ \
85 _s(SIGRTMIN+27, "Real-time signal 27"), /* 59 */ \
86 _s(SIGRTMIN+28, "Real-time signal 28"), /* 60 */ \
87 _s(SIGRTMIN+29, "Real-time signal 29"), /* 61 */ \
88 _s(SIGRTMIN+30, "Real-time signal 30"), /* 62 */ \
89 _s(SIGRTMIN+31, "Real-time signal 31"), /* 63 */ \
90 _s(SIGRTMAX, "Real-time signal 32") /* 64 */
92 #define _s(n, s) #n
93 #define _s2(n, s, n1, s1) #n
94 const char *sys_sigabbrev[] =
96 NULL,
97 __signals
100 #undef _s
101 #undef _s2
102 #define _s(n, s) s
103 #define _s2(n, s, n1, s1) s
104 const char *sys_siglist[] =
106 NULL,
107 __signals
110 #undef _s
111 #undef _s2
112 #define _s(n, s) {n, #n, s}
113 #define _s2(n, s, n1, s1) {n, #n, s}, {n, #n1, #s1}
114 static const sigdesc siglist[] =
116 __signals,
117 {0, NULL, NULL}
120 extern "C" char *
121 strsignal (int signo)
123 const char *sigstring = "Unknown signal %d";
124 for (int i = 0; siglist[i].n; i++)
125 if (siglist[i].n == signo)
127 sigstring = siglist[i].str;
128 break;
130 __small_sprintf (_my_tls.locals.signamebuf, sigstring, signo);
131 return _my_tls.locals.signamebuf;
134 extern "C" int
135 strtosigno (const char *name)
137 for (int i = 0; siglist[i].n; i++)
138 if (strcmp (siglist[i].name, name) == 0)
139 return siglist[i].n;
140 return 0;
143 #define ADD(str) \
145 v->iov_base = (void *)(str); \
146 v->iov_len = strlen ((char *)v->iov_base); \
147 v ++; \
148 iov_cnt ++; \
151 extern "C" void
152 psiginfo (const siginfo_t *info, const char *s)
154 struct iovec iov[5];
155 struct iovec *v = iov;
156 int iov_cnt = 0;
157 char buf[64];
159 if (s != NULL && *s != '\0')
161 ADD (s);
162 ADD (": ");
165 ADD (strsignal (info->si_signo));
167 if (info->si_signo > 0 && info->si_signo < _NSIG)
169 switch (info->si_signo)
171 case SIGILL:
172 case SIGBUS:
173 case SIGFPE:
174 case SIGSEGV:
175 snprintf (buf, sizeof(buf),
176 " (%d [%p])", info->si_code, info->si_addr);
177 break;
178 case SIGCHLD:
179 snprintf (buf, sizeof(buf),
180 " (%d %d %d %u)", info->si_code, info->si_pid,
181 info->si_status, info->si_uid);
182 break;
183 /* FIXME: implement si_band
184 case SIGPOLL:
185 fprintf (stderr, " (%d %ld)", info->si_code, info->si_band);
186 break;
188 default:
189 snprintf (buf, sizeof(buf),
190 " (%d %d %u)", info->si_code, info->si_pid,
191 info->si_uid);
193 ADD (buf);
196 #ifdef __SCLE
197 ADD ((stderr->_flags & __SCLE) ? "\r\n" : "\n");
198 #else
199 ADD ("\n");
200 #endif
202 fflush (stderr);
203 writev (fileno (stderr), iov, iov_cnt);