1 #include "shgetc.h"
2 #include "intscan.h"
3 #include <inttypes.h>
4 #include <limits.h>
5 #include <wctype.h>
6 #include <wchar.h>
7
wcstox(const wchar_t * restrict s,wchar_t ** restrict p,int base,unsigned long long lim)8 static unsigned long long wcstox(const wchar_t * restrict s,
9 wchar_t ** restrict p,
10 int base,
11 unsigned long long lim)
12 {
13 struct fake_file_t f;
14 wchar_t *t = (wchar_t *)s;
15 while (iswspace(*t)) t++;
16 shinit_wcstring(&f, t);
17 unsigned long long y = __intscan(&f, base, 1, lim);
18 if (p) {
19 size_t cnt = shcnt(&f);
20 *p = cnt ? t + cnt : (wchar_t *)s;
21 }
22 return y;
23 }
24
wcstoull(const wchar_t * restrict s,wchar_t ** restrict p,int base)25 unsigned long long wcstoull(const wchar_t *restrict s,
26 wchar_t **restrict p,
27 int base)
28 {
29 return wcstox(s, p, base, ULLONG_MAX);
30 }
31
wcstoll(const wchar_t * restrict s,wchar_t ** restrict p,int base)32 long long wcstoll(const wchar_t *restrict s, wchar_t **restrict p, int base)
33 {
34 return wcstox(s, p, base, LLONG_MIN);
35 }
36
wcstoul(const wchar_t * restrict s,wchar_t ** restrict p,int base)37 unsigned long wcstoul(const wchar_t *restrict s,
38 wchar_t **restrict p,
39 int base)
40 {
41 return wcstox(s, p, base, ULONG_MAX);
42 }
43
wcstol(const wchar_t * restrict s,wchar_t ** restrict p,int base)44 long wcstol(const wchar_t *restrict s, wchar_t **restrict p, int base)
45 {
46 return wcstox(s, p, base, 0UL+LONG_MIN);
47 }
48
wcstoimax(const wchar_t * restrict s,wchar_t ** restrict p,int base)49 intmax_t wcstoimax(const wchar_t *restrict s,
50 wchar_t **restrict p,
51 int base)
52 {
53 return wcstoll(s, p, base);
54 }
55
wcstoumax(const wchar_t * restrict s,wchar_t ** restrict p,int base)56 uintmax_t wcstoumax(const wchar_t *restrict s,
57 wchar_t **restrict p,
58 int base)
59 {
60 return wcstoull(s, p, base);
61 }
62