123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- #include <features.h>
- #include <string.h>
- #include <bits/uClibc_uintmaxtostr.h>
- #include <signal.h>
- #define _SYS_NSIG 32
- #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
- # define _SYS_SIGMSG_MAXLEN 25
- #else
- # define _SYS_SIGMSG_MAXLEN 0
- #endif
- #if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 15
- # define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 15)
- #else
- # define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
- #endif
- #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
- extern const char _string_syssigmsgs[] attribute_hidden;
- #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
- static const unsigned char sstridx[] = {
- 0,
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGIOT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
- #if defined SIGSTKFLT
- SIGSTKFLT,
- #else
- 0,
- #endif
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGIO,
- SIGPWR,
- SIGSYS,
- #if defined SIGEMT
- SIGEMT,
- #endif
- };
- #endif
- char *strsignal(int signum)
- {
- register char *s;
- int i;
- static char buf[_STRSIGNAL_BUFSIZE];
- static const char unknown[] = {
- 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
- };
- #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
-
- for (i = 0; i < sizeof(sstridx)/sizeof(sstridx[0]); i++) {
- if (sstridx[i] == signum) {
- goto GOT_SSTRIDX;
- }
- }
- i = INT_MAX;
- GOT_SSTRIDX:
- #else
-
- i = signum;
- #endif
- if (((unsigned int) signum) < _SYS_NSIG) {
-
- for (s = (char *) _string_syssigmsgs; i; ++s) {
- if (!*s) {
- --i;
- }
- }
- if (*s) {
- goto DONE;
- }
- }
- s = _int10tostr(buf + sizeof(buf)-1, signum) - sizeof(unknown);
- memcpy(s, unknown, sizeof(unknown));
- DONE:
- return s;
- }
- #else
- char *strsignal(int signum)
- {
- static char buf[_STRSIGNAL_BUFSIZE];
- static const char unknown[] = {
- 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
- };
- return memcpy(_int10tostr(buf + sizeof(buf)-1, signum) - sizeof(unknown),
- unknown, sizeof(unknown));
- }
- #endif
- libc_hidden_def(strsignal)
|