wcstol.c 332 B

123456789101112131415161718
  1. #include <wchar.h>
  2. #include <stdlib.h>
  3. #include <inttypes.h>
  4. #include <errno.h>
  5. #include <limits.h>
  6. long wcstol(const wchar_t *s, wchar_t **p, int base)
  7. {
  8. intmax_t x = wcstoimax(s, p, base);
  9. if (x > LONG_MAX) {
  10. errno = ERANGE;
  11. return LONG_MAX;
  12. } else if (x < LONG_MIN) {
  13. errno = ERANGE;
  14. return LONG_MIN;
  15. }
  16. return x;
  17. }