Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strerror.c
Go to the documentation of this file.
1 // Modeled after musl libc with the use of the errid[] and errmsg[] trick
2 
3 #include <errno.h>
4 #include <string.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(int err_no)
18 {
19  const char* s = NULL;
20  int i;
21 
22  for(i = 0; errid[i] && errid[i] != err_no; i++)
23  {
24  }
25 
26  for(s = errmsg; i; s++, i--)
27  {
28  for(; *s; s++)
29  {
30  }
31  }
32  return (char*)(uintptr_t)s;
33 }
char * strerror(int err_no)
Definition: strerror.c:17
#define NULL
Definition: stddef.h:15
static const unsigned char errid[]
Definition: strerror.c:7
static const char errmsg[]
Definition: strerror.c:13