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().
This commit is contained in:
Clemens Ladisch 2005-02-14 09:35:06 +00:00
parent f9b9015245
commit 49c9eba8e4

View 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;