strerror.c 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <errno.h>
  2. #include <stddef.h>
  3. #include <string.h>
  4. #include "locale_impl.h"
  5. /* mips has one error code outside of the 8-bit range due to a
  6. * historical typo, so we just remap it. */
  7. #if EDQUOT==1133
  8. #define EDQUOT_ORIG 1133
  9. #undef EDQUOT
  10. #define EDQUOT 109
  11. #endif
  12. static const struct errmsgstr_t {
  13. #define E(n, s) char str##n[sizeof(s)];
  14. #include "__strerror.h"
  15. #undef E
  16. } errmsgstr = {
  17. #define E(n, s) s,
  18. #include "__strerror.h"
  19. #undef E
  20. };
  21. static const unsigned short errmsgidx[] = {
  22. #define E(n, s) [n] = offsetof(struct errmsgstr_t, str##n),
  23. #include "__strerror.h"
  24. #undef E
  25. };
  26. char *__strerror_l(int e, locale_t loc)
  27. {
  28. const char *s;
  29. #ifdef EDQUOT_ORIG
  30. if (e==EDQUOT) e=0;
  31. else if (e==EDQUOT_ORIG) e=EDQUOT;
  32. #endif
  33. if (e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0;
  34. s = (char *)&errmsgstr + errmsgidx[e];
  35. return (char *)LCTRANS(s, LC_MESSAGES, loc);
  36. }
  37. char *strerror(int e)
  38. {
  39. return __strerror_l(e, CURRENT_LOCALE);
  40. }
  41. weak_alias(__strerror_l, strerror_l);