1 #include "floatscan.h"
2 #include "libc.h"
3 #include "shgetc.h"
4 #include "stdio_impl.h"
5 #include <stdlib.h>
6 
strtox(const char * s,char ** p,int prec)7 static long double strtox(const char* s, char** p, int prec) {
8     FILE f = {.buf = (void*)s, .rpos = (void*)s, .rend = (void*)-1, .lock = -1};
9     shlim(&f, 0);
10     long double y = __floatscan(&f, prec, 1);
11     off_t cnt = shcnt(&f);
12     if (p)
13         *p = cnt ? (char*)s + cnt : (char*)s;
14     return y;
15 }
16 
strtof(const char * restrict s,char ** restrict p)17 float strtof(const char* restrict s, char** restrict p) {
18     return strtox(s, p, 0);
19 }
20 
strtod(const char * restrict s,char ** restrict p)21 double strtod(const char* restrict s, char** restrict p) {
22     return strtox(s, p, 1);
23 }
24 
strtold(const char * restrict s,char ** restrict p)25 long double strtold(const char* restrict s, char** restrict p) {
26     return strtox(s, p, 2);
27 }
28