1
0

regerror.c 984 B

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