| 1 | #include <errno.h> |
| 2 | #include <stddef.h> |
| 3 | #include <string.h> |
| 4 | #include "locale_impl.h" |
| 5 | |
| 6 | /* mips has one error code outside of the 8-bit range due to a |
| 7 | * historical typo, so we just remap it. */ |
| 8 | #if EDQUOT==1133 |
| 9 | #define EDQUOT_ORIG 1133 |
| 10 | #undef EDQUOT |
| 11 | #define EDQUOT 109 |
| 12 | #endif |
| 13 | |
| 14 | static const struct errmsgstr_t { |
| 15 | #define E(n, s) char str##n[sizeof(s)]; |
| 16 | #include "__strerror.h" |
| 17 | #undef E |
| 18 | } errmsgstr = { |
| 19 | #define E(n, s) s, |
| 20 | #include "__strerror.h" |
| 21 | #undef E |
| 22 | }; |
| 23 | |
| 24 | static const unsigned short errmsgidx[] = { |
| 25 | #define E(n, s) [n] = offsetof(struct errmsgstr_t, str##n), |
| 26 | #include "__strerror.h" |
| 27 | #undef E |
| 28 | }; |
| 29 | |
| 30 | char *__strerror_l(int e, locale_t loc) |
| 31 | { |
| 32 | 	const char *s; |
| 33 | #ifdef EDQUOT_ORIG |
| 34 | 	if (e==EDQUOT) e=0; |
| 35 | 	else if (e==EDQUOT_ORIG) e=EDQUOT; |
| 36 | #endif |
| 37 | 	if (e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0; |
| 38 | 	s = (char *)&errmsgstr + errmsgidx[e]; |
| 39 | 	return (char *)LCTRANS(s, LC_MESSAGES, loc); |
| 40 | } |
| 41 | |
| 42 | char *strerror(int e) |
| 43 | { |
| 44 | 	return __strerror_l(e, CURRENT_LOCALE); |
| 45 | } |
| 46 | |
| 47 | weak_alias(__strerror_l, strerror_l); |