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.
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? */
18 #include <bits/uClibc_uintmaxtostr.h>
23 #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
24 # define _SYS_SIGMSG_MAXLEN 25
26 # define _SYS_SIGMSG_MAXLEN 0
29 #if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 15
30 # define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 15)
32 # define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
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
[] = {
83 char *strsignal(int signum
)
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
) {
99 i
= INT_MAX
; /* Failed. */
102 /* No signum to string index translation needed. */
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
111 for (s
= (char *) _string_syssigmsgs
; i
; ++s
) {
116 if (*s
) { /* Make sure we have an actual message. */
121 s
= _int10tostr(buf
+ sizeof(buf
)-1, signum
) - sizeof(unknown
);
122 memcpy(s
, unknown
, sizeof(unknown
));
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
)