3 #include "stdio_impl.h"
7 /* This read function heavily cheats. It knows:
8 * (1) len will always be 1
9 * (2) non-ascii characters don't matter */
11 static size_t do_read(FILE *f
, unsigned char *buf
, size_t len
)
14 const wchar_t *wcs
= f
->cookie
;
16 if (!wcs
[0]) wcs
=L
"@";
17 for (i
=0; i
<f
->buf_size
&& wcs
[i
]; i
++)
18 f
->buf
[i
] = wcs
[i
] < 128 ? wcs
[i
] : '@';
21 f
->cookie
= (void *)(wcs
+i
);
30 static long double wcstox(const wchar_t *s
, wchar_t **p
, int prec
)
32 wchar_t *t
= (wchar_t *)s
;
33 unsigned char buf
[64];
38 f
.buf_size
= sizeof buf
- 4;
41 while (iswspace(*t
)) t
++;
44 long double y
= __floatscan(&f
, prec
, 1);
46 size_t cnt
= shcnt(&f
);
47 *p
= cnt
? t
+ cnt
: (wchar_t *)s
;
52 float wcstof(const wchar_t *restrict s
, wchar_t **restrict p
)
54 return wcstox(s
, p
, 0);
57 double wcstod(const wchar_t *restrict s
, wchar_t **restrict p
)
59 return wcstox(s
, p
, 1);
62 long double wcstold(const wchar_t *restrict s
, wchar_t **restrict p
)
64 return wcstox(s
, p
, 2);