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
This commit is contained in:
columbarius 2022-04-03 00:56:37 +02:00 committed by Wim Taymans
parent 54f6f9293e
commit f36f673b3b

View file

@ -279,10 +279,9 @@ static inline float spa_strtof(const char *str, char **endptr)
float v; float v;
if (SPA_UNLIKELY(locale == NULL)) if (SPA_UNLIKELY(locale == NULL))
locale = newlocale(LC_ALL_MASK, "C", NULL); locale = newlocale(LC_ALL_MASK, "C", NULL);
if (locale != NULL) locale_t prev = uselocale(locale);
v = strtof_l(str, endptr, locale); v = strtof(str, endptr);
else uselocale(prev);
v = strtof(str, endptr);
return v; return v;
} }
@ -323,10 +322,9 @@ static inline double spa_strtod(const char *str, char **endptr)
double v; double v;
if (SPA_UNLIKELY(locale == NULL)) if (SPA_UNLIKELY(locale == NULL))
locale = newlocale(LC_ALL_MASK, "C", NULL); locale = newlocale(LC_ALL_MASK, "C", NULL);
if (locale != NULL) locale_t prev = uselocale(locale);
v = strtod_l(str, endptr, locale); v = strtod(str, endptr);
else uselocale(prev);
v = strtod(str, endptr);
return v; return v;
} }