diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 052a39172..1444361e9 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -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) diff --git a/configure.ac b/configure.ac index ebaceb1de..7070799ff 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ) diff --git a/src/fallback.cpp b/src/fallback.cpp index 42a9d62d2..d7e4e508e 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -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) diff --git a/src/fallback.h b/src/fallback.h index 44ddee398..b0680de05 100644 --- a/src/fallback.h +++ b/src/fallback.h @@ -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