]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/stdlib/wcstol.c
1 #include "stdio_impl.h"
9 /* This read function heavily cheats. It knows:
10 * (1) len will always be 1
11 * (2) non-ascii characters don't matter */
13 static size_t do_read(FILE *f
, unsigned char *buf
, size_t len
)
16 const wchar_t *wcs
= f
->cookie
;
18 if (!wcs
[0]) wcs
=L
"@";
19 for (i
=0; i
<f
->buf_size
&& wcs
[i
]; i
++)
20 f
->buf
[i
] = wcs
[i
] < 128 ? wcs
[i
] : '@';
23 f
->cookie
= (void *)(wcs
+i
);
32 static unsigned long long wcstox(const wchar_t *s
, wchar_t **p
, int base
, unsigned long long lim
)
34 wchar_t *t
= (wchar_t *)s
;
35 unsigned char buf
[64];
40 f
.buf_size
= sizeof buf
- 4;
41 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
45 while (iswspace(*t
)) t
++;
48 unsigned long long y
= __intscan(&f
, base
, 1, lim
);
50 size_t cnt
= shcnt(&f
);
51 *p
= cnt
? t
+ cnt
: (wchar_t *)s
;
56 unsigned long long wcstoull(const wchar_t *restrict s
, wchar_t **restrict p
, int base
)
58 return wcstox(s
, p
, base
, ULLONG_MAX
);
61 long long wcstoll(const wchar_t *restrict s
, wchar_t **restrict p
, int base
)
63 return wcstox(s
, p
, base
, LLONG_MIN
);
66 unsigned long wcstoul(const wchar_t *restrict s
, wchar_t **restrict p
, int base
)
68 return wcstox(s
, p
, base
, ULONG_MAX
);
71 long wcstol(const wchar_t *restrict s
, wchar_t **restrict p
, int base
)
73 return wcstox(s
, p
, base
, 0UL+LONG_MIN
);
76 intmax_t wcstoimax(const wchar_t *restrict s
, wchar_t **restrict p
, int base
)
78 return wcstoll(s
, p
, base
);
81 uintmax_t wcstoumax(const wchar_t *restrict s
, wchar_t **restrict p
, int base
)
83 return wcstoull(s
, p
, base
);