From 62f828014f17596cf8fb5cd2ea0c34cb754f75cb Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 10 Mar 2013 22:51:11 -0500 Subject: Use C locale when parsing UseDelta floating point values We should save the current locale, use the 'C' locale during parsing, then restore the original locale. Config files should always parse regardless of the current user's locale setting. Fixes FS#34253. Signed-off-by: Dan McGee Signed-off-by: Allan McRae --- src/pacman/conf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 815df95f..3f1b1c39 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -21,6 +21,7 @@ #include #include #include +#include /* setlocale */ #include /* open */ #include #include @@ -514,7 +515,15 @@ static int _parse_options(const char *key, char *value, } else if(strcmp(key, "UseDelta") == 0) { double ratio; char *endptr; + const char *oldlocale; + + /* set the locale to 'C' for consistant decimal parsing (0.7 and never + * 0,7) from config files, then restore old setting when we are done */ + oldlocale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); ratio = strtod(value, &endptr); + setlocale(LC_NUMERIC, oldlocale); + if(*endptr != '\0' || ratio < 0.0 || ratio > 2.0) { pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: invalid value for '%s' : '%s'\n"), -- cgit v1.2.3-24-g4f1b