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