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.
8 /* get rid of REDIRECT */
9 #define strerror_r __hide_strerror_r
14 #include "_syserrmsg.h"
18 #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
20 extern const char _string_syserrmsgs
[] attribute_hidden
;
22 #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
24 static const unsigned char estridx
[] = {
25 0, /* success is always 0 */
147 #if EDQUOT > 200 /* mips has an outrageous value for this... */
154 #if EDEADLOCK != EDEADLK
161 int __xpg_strerror_r(int errnum
, char *strerrbuf
, size_t buflen
)
165 char buf
[_STRERROR_BUFSIZE
];
166 static const char unknown
[] = {
167 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
173 #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
175 #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
176 /* Need to translate errno to string index. */
177 for (i
= 0 ; i
< sizeof(estridx
)/sizeof(estridx
[0]) ; i
++) {
178 if (estridx
[i
] == errnum
) {
182 i
= INT_MAX
; /* Failed, but may need to check mips special case. */
183 #if EDQUOT > 200 /* Deal with large EDQUOT value on mips */
184 if (errnum
== EDQUOT
)
189 /* No errno to string index translation needed. */
193 if (((unsigned int) i
) < _SYS_NERR
) {
194 /* Trade time for space. This function should rarely be called
195 * so rather than keeping an array of pointers for the different
196 * messages, just run through the buffer until we find the
198 for (s
= (char *) _string_syserrmsgs
; i
; ++s
) {
203 if (*s
) { /* Make sure we have an actual message. */
209 #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
211 s
= _int10tostr(buf
+sizeof(buf
)-1, errnum
) - sizeof(unknown
);
212 memcpy(s
, unknown
, sizeof(unknown
));
215 if (!strerrbuf
) { /* SUSv3 */
225 memcpy(strerrbuf
, s
, i
);
226 strerrbuf
[i
-1] = 0; /* In case buf was too small. */
236 #else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
238 int __xpg_strerror_r(int errnum
, char *strerrbuf
, size_t buflen
)
242 char buf
[_STRERROR_BUFSIZE
];
243 static const char unknown
[] = {
244 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
247 s
= _int10tostr(buf
+sizeof(buf
)-1, errnum
) - sizeof(unknown
);
248 memcpy(s
, unknown
, sizeof(unknown
));
250 if (!strerrbuf
) { /* SUSv3 */
256 i
= buf
+ sizeof(buf
) - s
;
264 memcpy(strerrbuf
, s
, i
);
265 strerrbuf
[i
-1] = 0; /* In case buf was too small. */
273 #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
274 libc_hidden_def(__xpg_strerror_r
)
275 #if defined __USE_XOPEN2K && !defined __USE_GNU
276 strong_alias(__xpg_strerror_r
,strerror_r
)