]> git.alsa-project.org Git - alsa-lib.git/commitdiff
use "C" locale when parsing floating point numbers
authorClemens Ladisch <clemens@ladisch.de>
Mon, 14 Feb 2005 09:35:06 +0000 (09:35 +0000)
committerClemens Ladisch <clemens@ladisch.de>
Mon, 14 Feb 2005 09:35:06 +0000 (09:35 +0000)
Floating point numbers in configuration files always use "." as separator,
so set the locale temporarily to "C" when calling strtod().

src/conf.c

index 4ef2a6ae7d8aa40702fb6ebe29af1047326cc04c..066e07e1e31fbe8b04e7894e690fc14d9834d455 100644 (file)
@@ -420,6 +420,7 @@ beginning:</P>
 #include <limits.h>
 #include <sys/stat.h>
 #include <pthread.h>
+#include <locale.h>
 #include "local.h"
 
 #ifndef DOC_HIDDEN
@@ -497,12 +498,19 @@ static int safe_strtod(const char *str, double *val)
 {
        char *end;
        double v;
+       char *saved_locale;
+       int err;
+
        if (!*str)
                return -EINVAL;
+       saved_locale = setlocale(LC_NUMERIC, NULL);
+       setlocale(LC_NUMERIC, "C");
        errno = 0;
        v = strtod(str, &end);
-       if (errno)
-               return -errno;
+       err = -errno;
+       setlocale(LC_NUMERIC, saved_locale);
+       if (err)
+               return err;
        if (*end)
                return -EINVAL;
        *val = v;