From f36f673b3b47bedddabfdce766b895e7f4383387 Mon Sep 17 00:00:00 2001 From: columbarius Date: Sun, 3 Apr 2022 00:56:37 +0200 Subject: [PATCH] spa: replace locale aware string functions with uselocale Not all string functions have a POSIX compliant locale aware version (eg. strtof_l). Instead uselocale [1] should be used, which allows switching the locale of a thread to a welldefined one and restoring it afterwards. [1] https://man7.org/linux/man-pages/man3/uselocale.3.html --- spa/include/spa/utils/string.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spa/include/spa/utils/string.h b/spa/include/spa/utils/string.h index 080536050..e80434537 100644 --- a/spa/include/spa/utils/string.h +++ b/spa/include/spa/utils/string.h @@ -279,10 +279,9 @@ static inline float spa_strtof(const char *str, char **endptr) float v; if (SPA_UNLIKELY(locale == NULL)) locale = newlocale(LC_ALL_MASK, "C", NULL); - if (locale != NULL) - v = strtof_l(str, endptr, locale); - else - v = strtof(str, endptr); + locale_t prev = uselocale(locale); + v = strtof(str, endptr); + uselocale(prev); return v; } @@ -323,10 +322,9 @@ static inline double spa_strtod(const char *str, char **endptr) double v; if (SPA_UNLIKELY(locale == NULL)) locale = newlocale(LC_ALL_MASK, "C", NULL); - if (locale != NULL) - v = strtod_l(str, endptr, locale); - else - v = strtod(str, endptr); + locale_t prev = uselocale(locale); + v = strtod(str, endptr); + uselocale(prev); return v; }