upgrade to latest upstream TRE regex code (0.8.0)
[musl] / src / regex / regerror.c
1 #include <string.h>
2 #include <regex.h>
3 #include <stdio.h>
4
5 /* Error message strings for error codes listed in `regex.h'.  This list
6    needs to be in sync with the codes listed there, naturally. */
7
8 /* Converted to single string by Rich Felker to remove the need for
9  * data relocations at runtime, 27 Feb 2006. */
10
11 static const char messages[] = {
12   "No error\0"
13   "No match\0"
14   "Invalid regexp\0"
15   "Unknown collating element\0"
16   "Unknown character class name\0"
17   "Trailing backslash\0"
18   "Invalid back reference\0"
19   "Missing ']'\0"
20   "Missing ')'\0"
21   "Missing '}'\0"
22   "Invalid contents of {}\0"
23   "Invalid character range\0"
24   "Out of memory\0"
25   "XXX\0"
26   "\0Unknown error"
27 };
28
29 size_t regerror(int e, const regex_t *preg, char *buf, size_t size)
30 {
31         const char *s;
32         for (s=messages; e && *s; e--, e+=strlen(s)+1);
33         if (!*s) s++;
34         return 1+snprintf(buf, size, "%s", s);
35 }