1 #include "stdio_impl.h"
5 /* This read function heavily cheats. It knows:
6 * (1) len will always be 1
7 * (2) non-ascii characters don't matter */
9 static size_t do_read(FILE *f, unsigned char *buf, size_t len)
12 const wchar_t *wcs = f->cookie;
14 for (i=0; i<f->buf_size && wcs[i]; i++)
15 f->buf[i] = wcs[i] < 128 ? wcs[i] : '@';
18 f->cookie = (void *)(wcs+i);
27 static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsigned long long lim)
29 unsigned char buf[64];
34 f.buf_size = sizeof buf;
39 unsigned long long y = __intscan(&f, base, 1, lim);
41 size_t cnt = shcnt(&f);
42 *p = (wchar_t *)s + cnt;
47 unsigned long long wcstoull(const wchar_t *s, wchar_t **p, int base)
49 return wcstox(s, p, base, ULLONG_MAX);
52 long long wcstoll(const wchar_t *s, wchar_t **p, int base)
54 return wcstox(s, p, base, LLONG_MIN);
57 unsigned long wcstoul(const wchar_t *s, wchar_t **p, int base)
59 return wcstox(s, p, base, ULONG_MAX);
62 long wcstol(const wchar_t *s, wchar_t **p, int base)
64 return wcstox(s, p, base, 0UL+LONG_MIN);
67 intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base)
69 return wcstoll(s, p, base);
72 uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
74 return wcstoull(s, p, base);