2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
11 #include "_syserrmsg.h"
13 #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
15 extern const char _string_syserrmsgs[] attribute_hidden;
17 #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
19 static const unsigned char estridx[] = {
20 0, /* success is always 0 */
142 #if EDQUOT > 200 /* mips has an outrageous value for this... */
149 #if EDEADLOCK != EDEADLK
156 int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen)
160 char buf[_STRERROR_BUFSIZE];
161 static const char unknown[] = {
162 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
168 #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
170 #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
171 /* Need to translate errno to string index. */
172 for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) {
173 if (estridx[i] == errnum) {
177 i = INT_MAX; /* Failed, but may need to check mips special case. */
178 #if EDQUOT > 200 /* Deal with large EDQUOT value on mips */
179 if (errnum == EDQUOT)
184 /* No errno to string index translation needed. */
188 if (((unsigned int) i) < _SYS_NERR) {
189 /* Trade time for space. This function should rarely be called
190 * so rather than keeping an array of pointers for the different
191 * messages, just run through the buffer until we find the
193 for (s = (char *) _string_syserrmsgs ; i ; ++s) {
198 if (*s) { /* Make sure we have an actual message. */
204 #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
206 s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
207 memcpy(s, unknown, sizeof(unknown));
210 if (!strerrbuf) { /* SUSv3 */
220 memcpy(strerrbuf, s, i);
221 strerrbuf[i-1] = 0; /* In case buf was too small. */
231 #else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
233 int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen)
237 char buf[_STRERROR_BUFSIZE];
238 static const char unknown[] = {
239 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
242 s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
243 memcpy(s, unknown, sizeof(unknown));
245 if (!strerrbuf) { /* SUSv3 */
251 i = buf + sizeof(buf) - s;
259 memcpy(strerrbuf, s, i);
260 strerrbuf[i-1] = 0; /* In case buf was too small. */
268 #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
269 libc_hidden_def(__xpg_strerror_r)
270 strong_alias_untyped(__xpg_strerror_r, strerror_r)