1 #include <stdlib.h>
2 #include "shgetc.h"
3 #include "floatscan.h"
4 #include "stdio_impl.h"
5
strtox(const char * s,char ** p,int prec)6 static long double strtox(const char *s, char **p, int prec)
7 {
8 FILE f;
9 sh_fromstring(&f, s);
10 shlim(&f, 0);
11 long double y = __floatscan(&f, prec, 1);
12 off_t cnt = shcnt(&f);
13 if (p) *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 {
19 return strtox(s, p, 0);
20 }
21
strtod(const char * restrict s,char ** restrict p)22 double strtod(const char *restrict s, char **restrict p)
23 {
24 return strtox(s, p, 1);
25 }
26
strtold(const char * restrict s,char ** restrict p)27 long double strtold(const char *restrict s, char **restrict p)
28 {
29 return strtox(s, p, 2);
30 }
31
32 weak_alias(strtof, strtof_l);
33 weak_alias(strtod, strtod_l);
34 weak_alias(strtold, strtold_l);
35 weak_alias(strtof, __strtof_l);
36 weak_alias(strtod, __strtod_l);
37 weak_alias(strtold, __strtold_l);
38