24c94d3742d4ed013dea3ef5625bfc03fd189a05
[musl] / src / errno / strerror.c
1 #include <errno.h>
2 #include <string.h>
3 #include "locale_impl.h"
4 #include "libc.h"
5
6 #define E(a,b) ((unsigned char)a),
7 static const unsigned char errid[] = {
8 #include "__strerror.h"
9 };
10
11 #undef E
12 #define E(a,b) b "\0"
13 static const char errmsg[] =
14 #include "__strerror.h"
15 ;
16
17 char *__strerror_l(int e, locale_t loc)
18 {
19         const char *s;
20         int i;
21         /* mips has one error code outside of the 8-bit range due to a
22          * historical typo, so we just remap it. */
23         if (EDQUOT==1133) {
24                 if (e==109) e=-1;
25                 else if (e==EDQUOT) e=109;
26         }
27         for (i=0; errid[i] && errid[i] != e; i++);
28         for (s=errmsg; i; s++, i--) for (; *s; s++);
29         return (char *)LCTRANS(s, LC_MESSAGES, loc);
30 }
31
32 char *strerror(int e)
33 {
34         return __strerror_l(e, CURRENT_LOCALE);
35 }
36
37 weak_alias(__strerror_l, strerror_l);