static long double strtox(const char *s, char **p, int prec) { char *t = (char *)s; while (isspace(*t)) t++; FILE f = { .buf = (void *)t, .rpos = (void *)t, .rend = (void *)-1, .lock = -1 }; shlim(&f, 0); long double y = __floatscan(&f, -1, prec, 1); off_t cnt = shcnt(&f); if (p) *p = cnt ? t + cnt : (char *)s; return y; } float strtof(const char *s, char **p) { return strtox(s, p, 0); } double strtod(const char *s, char **p) { return strtox(s, p, 1); } long double strtold(const char *s, char **p) { return strtox(s, p, 2); }
static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim) { /* FIXME: use a helper function or macro to setup the FILE */ FILE f; f.flags = 0; f.buf = f.rpos = (void *)s; if ((size_t)s > (size_t)-1/2) f.rend = (void *)-1; else f.rend = (unsigned char *)s+(size_t)-1/2; f.lock = -1; shlim(&f, 0); unsigned long long y = __intscan(&f, base, 1, lim); if (p) { size_t cnt = shcnt(&f); *p = (char *)s + cnt; } return y; }
static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsigned long long lim) { wchar_t *t = (wchar_t *)s; unsigned char buf[64]; FILE f = {0}; f.flags = 0; f.rpos = f.rend = 0; f.buf = buf + 4; f.buf_size = sizeof buf - 4; f.lock = -1; f.read = do_read; while (iswspace(*t)) t++; f.cookie = (void *)t; shlim(&f, 0); unsigned long long y = __intscan(&f, base, 1, lim); if (p) { size_t cnt = shcnt(&f); *p = cnt ? t + cnt : (wchar_t *)s; } return y; }
/* @LICENSE(MUSLC_MIT) */ #include <stdlib.h> #include "shgetc.h" #include "floatscan.h" #include "stdio_impl.h" static long double strtox(const char *s, char **p, int prec) { FILE f = { .buf = (void *)s, .rpos = (void *)s, .rend = (void *)-1, .lock = -1 }; shlim(&f, 0); long double y = __floatscan(&f, prec, 1); off_t cnt = shcnt(&f); if (p) *p = cnt ? (char *)s + cnt : (char *)s; return y; } float strtof(const char *s, char **p) { return strtox(s, p, 0); } double strtod(const char *s, char **p) { return strtox(s, p, 1); } long double strtold(const char *s, char **p)