sparc64: add basic support
[uclibc-ng.git] / libc / string / strsignal.c
blob0fbbf85045200b7d6803e51316d21e67c3208c8d
1 /*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
8 /*
9 * Sep 11, 2003
10 * Patch by Atsushi Nemoto <anemo@mba.ocn.ne.jp> to do arch-required
11 * mapping of signal strings (alpha, mips, hppa, sparc).
14 /* TODO: make a threadsafe version? */
16 #include <features.h>
17 #include <string.h>
18 #include <bits/uClibc_uintmaxtostr.h>
19 #include <signal.h>
21 #define _SYS_NSIG 32
23 #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
24 # define _SYS_SIGMSG_MAXLEN 25
25 #else
26 # define _SYS_SIGMSG_MAXLEN 0
27 #endif
29 #if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 15
30 # define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 15)
31 #else
32 # define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
33 #endif
35 #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
37 extern const char _string_syssigmsgs[] attribute_hidden;
39 #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
40 static const unsigned char sstridx[] = {
42 SIGHUP,
43 SIGINT,
44 SIGQUIT,
45 SIGILL,
46 SIGTRAP,
47 SIGIOT,
48 SIGBUS,
49 SIGFPE,
50 SIGKILL,
51 SIGUSR1,
52 SIGSEGV,
53 SIGUSR2,
54 SIGPIPE,
55 SIGALRM,
56 SIGTERM,
57 #if defined SIGSTKFLT
58 SIGSTKFLT,
59 #else
61 #endif
62 SIGCHLD,
63 SIGCONT,
64 SIGSTOP,
65 SIGTSTP,
66 SIGTTIN,
67 SIGTTOU,
68 SIGURG,
69 SIGXCPU,
70 SIGXFSZ,
71 SIGVTALRM,
72 SIGPROF,
73 SIGWINCH,
74 SIGIO,
75 SIGPWR,
76 SIGSYS,
77 #if defined SIGEMT
78 SIGEMT,
79 #endif
81 #endif
83 char *strsignal(int signum)
85 register char *s;
86 int i;
87 static char buf[_STRSIGNAL_BUFSIZE];
88 static const char unknown[] = {
89 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
92 #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
93 /* Need to translate signum to string index. */
94 for (i = 0; i < sizeof(sstridx)/sizeof(sstridx[0]); i++) {
95 if (sstridx[i] == signum) {
96 goto GOT_SSTRIDX;
99 i = INT_MAX; /* Failed. */
100 GOT_SSTRIDX:
101 #else
102 /* No signum to string index translation needed. */
103 i = signum;
104 #endif
106 if (((unsigned int) signum) < _SYS_NSIG) {
107 /* Trade time for space. This function should rarely be called
108 * so rather than keeping an array of pointers for the different
109 * messages, just run through the buffer until we find the
110 * correct string. */
111 for (s = (char *) _string_syssigmsgs; i; ++s) {
112 if (!*s) {
113 --i;
116 if (*s) { /* Make sure we have an actual message. */
117 goto DONE;
121 s = _int10tostr(buf + sizeof(buf)-1, signum) - sizeof(unknown);
122 memcpy(s, unknown, sizeof(unknown));
124 DONE:
125 return s;
128 #else /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
130 char *strsignal(int signum)
132 static char buf[_STRSIGNAL_BUFSIZE];
133 static const char unknown[] = {
134 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
137 return memcpy(_int10tostr(buf + sizeof(buf)-1, signum) - sizeof(unknown),
138 unknown, sizeof(unknown));
141 #endif /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
143 libc_hidden_def(strsignal)