Files
haiku-beta6/src/system/libroot/posix/musl/stdlib/strtod.c
T
Augustin Cavalier 7174197a8d libroot/posix: Switch to using musl's string-integer/float conversion routines.
Unlike glibc's, these don't take the current locale into account.
The POSIX specification says: "In other than the C and POSIX locales,
other implementation-defined subject sequences may be accepted."
Not accepting any other than the default seems to be more consistent
regardless.

This also makes things consistent between wchar_t and char, as we
were using the BSD implementations of strto*l for regular chars
but glibc's for wcsto*l before.
2025-04-07 16:20:36 -04:00

39 lines
742 B
C

#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;
sh_fromstring(&f, s);
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 *restrict s, char **restrict p)
{
return strtox(s, p, 0);
}
double strtod(const char *restrict s, char **restrict p)
{
return strtox(s, p, 1);
}
long double strtold(const char *restrict s, char **restrict p)
{
return strtox(s, p, 2);
}
#ifdef __HAIKU__
weak_alias(strtof, __strtof_internal);
weak_alias(strtod, __strtod_internal);
weak_alias(strtold, __strtold_internal);
#endif