1
0

regerror.c 938 B

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