strerror.c 747 B

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