strerror.c 765 B

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