123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #define WANT_SIGLIST 1
- #include <stdlib.h>
- #include <malloc.h>
- #include <signal.h>
- #include <limits.h>
- #define __USE_GNU
- #include <string.h>
- #if (INT_MAX >> 31)
- #error need to check size allocation for static buffer 'retbuf'
- #endif
- extern char *__ltostr(char *buf, long uval, int base, int uppercase);
- #ifdef L_strsignal
- #if WANT_SIGLIST
- const char *const sys_siglist[] = {
- "Unknown signal",
- "Hangup",
- "Interrupt",
- "Quit",
- "Illegal instruction",
- "Trace/breakpoint trap",
- "IOT trap/Abort",
- "Bus error",
- "Floating point exception",
- "Killed",
- "User defined signal 1",
- "Segmentation fault",
- "User defined signal 2",
- "Broken pipe",
- "Alarm clock",
- "Terminated",
- "Stack fault",
- "Child exited",
- "Continued",
- "Stopped (signal)",
- "Stopped",
- "Stopped (tty input)",
- "Stopped (tty output)",
- "Urgent condition",
- "CPU time limit exceeded",
- "File size limit exceeded",
- "Virtual time alarm",
- "Profile signal",
- "Window size changed",
- "Possible I/O",
- "Power failure",
- "Unused signal",
- NULL
- };
- #endif
- #define NUM_KNOWN_SIGNALS 32
- static char retbuf[28];
- static const char unknown_signal[] = "Unknown Signal:";
- char *strsignal(int sig)
- {
- char *pos;
- #ifdef WANT_SIGLIST
-
-
- if ((sig >= 0) && (sig < NUM_KNOWN_SIGNALS)) {
- strcpy(retbuf, sys_siglist[sig]);
- return retbuf;
- }
- #endif
- pos = __ltostr(retbuf + sizeof(unknown_signal) + 1, sig, 10, 0)
- - sizeof(unknown_signal);
- strcpy(pos, unknown_signal);
- *(pos + sizeof(unknown_signal) - 1) = ' ';
- return pos;
- }
- #endif
- #ifdef L_psignal
- #include <stdio.h>
- void psignal(int sig, const char *s)
- {
- fprintf(stderr, "%s: %s\n", s, strsignal(sig));
- }
- #endif
- #ifdef CHECK_BUF
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- int max = 0;
- int j, retcode;
- const char *p;
- #if WANT_SIGLIST
- int i;
- #endif
- retcode = EXIT_SUCCESS;
- #if WANT_SIGLIST
-
- for ( i=0 ; sys_siglist[i] ; i++ ) {
- j = strlen(sys_siglist[i])+1;
- if (j > max) max = j;
- }
- if (i != NUM_KNOWN_SIGNALS) {
- printf("Error: strsignal.c - NUM_KNOWN_SIGNALS should be %d\n", i);
- retcode = EXIT_FAILURE;
- }
- #endif
- p = strsignal(INT_MIN);
- j = strlen(p)+1;
- if (j > max) max = j;
-
- if (sizeof(retbuf) != max) {
- printf("Error: strsignal.c - dimension of retbuf should be = %d\n", max);
- retcode = EXIT_FAILURE;
- }
-
- printf("Passed.\n");
- return retcode;
- }
- #endif
|