From: Clemens Ladisch
Date: Mon, 14 Feb 2005 09:35:06 +0000 (+0000)
Subject: use "C" locale when parsing floating point numbers
X-Git-Tag: v1.0.9rc1~25
X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=49c9eba8e4cdfa4ca40e8271e25dfb666c130cd5;p=alsa-lib.git
use "C" locale when parsing floating point numbers
Floating point numbers in configuration files always use "." as separator,
so set the locale temporarily to "C" when calling strtod().
---
diff --git a/src/conf.c b/src/conf.c
index 4ef2a6ae..066e07e1 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -420,6 +420,7 @@ beginning:
#include
#include
#include
+#include
#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;