libalsa/libalsa-1.0.23-thread_safe_locale.patch

35 lines
822 B
Diff
Raw Permalink Normal View History

diff --git a/src/conf.c b/src/conf.c
index 570c90f..ce252ab 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -499,22 +499,20 @@ static int safe_strtod(const char *str, double *val)
{
char *end;
double v;
- char *saved_locale;
- char locstr[64]; /* enough? */
+ locale_t saved_locale, c_locale;
int err;
if (!*str)
return -EINVAL;
- saved_locale = setlocale(LC_NUMERIC, NULL);
- if (saved_locale) {
- snprintf(locstr, sizeof(locstr), "%s", saved_locale);
- setlocale(LC_NUMERIC, "C");
- }
+ c_locale = newlocale(LC_NUMERIC_MASK, "C", 0);
+ saved_locale = uselocale(c_locale);
errno = 0;
v = strtod(str, &end);
err = -errno;
- if (saved_locale)
- setlocale(LC_NUMERIC, locstr);
+ if (c_locale != (locale_t)0) {
+ uselocale(saved_locale);
+ freelocale(c_locale);
+ }
if (err)
return err;
if (*end)