Add fallback wcstod_l for musl

Just sets locale to "C" (because that's the only one we need), does
wcstod and resets the locale.

No idea why uselocale(loc) failed for me, but it did.

Fixes #5407.
This commit is contained in:
Fabian Homborg 2018-12-12 15:12:12 +01:00
parent 355cb88e38
commit ffab420e43
4 changed files with 21 additions and 0 deletions

View file

@ -72,6 +72,7 @@ CHECK_CXX_SYMBOL_EXISTS(wcsdup wchar.h HAVE_WCSDUP)
CHECK_CXX_SYMBOL_EXISTS(wcslcpy wchar.h HAVE_WCSLCPY)
CHECK_CXX_SYMBOL_EXISTS(wcsncasecmp wchar.h HAVE_WCSNCASECMP)
CHECK_CXX_SYMBOL_EXISTS(wcsndup wchar.h HAVE_WCSNDUP)
CHECK_CXX_SYMBOL_EXISTS(wcstod_l wchar.h HAVE_WCSTOD_L)
CHECK_CXX_SYMBOL_EXISTS(_sys_errs stdlib.h HAVE__SYS__ERRS)

View file

@ -316,6 +316,7 @@ AC_STRUCT_DIRENT_D_TYPE
#
AC_CHECK_FUNCS( wcsndup )
AC_CHECK_FUNCS( wcstod_l )
AC_CHECK_FUNCS( futimes )
AC_CHECK_FUNCS( wcslcpy lrand48_r killpg )
AC_CHECK_FUNCS( backtrace_symbols getifaddrs )

View file

@ -388,3 +388,18 @@ int flock(int fd, int op) {
}
#endif // HAVE_FLOCK
#ifndef HAVE_WCSTOD_L
// musl doesn't feature wcstod_l,
// so we just wrap wcstod.
double wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc) {
char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL));
// Yes, this is hardcoded to use the "C" locale.
// That's the only thing we need, and uselocale(loc) broke in my testing.
setlocale(LC_NUMERIC, "C");
double ret = wcstod(enptr, endptr);
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);
return ret;
}
#endif // defined(wcstod_l)

View file

@ -198,3 +198,7 @@ int flock(int fd, int op);
#endif
#endif
#ifndef wcstod_l
double wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc);
#endif