diff options
author | Dan McGee <dan@archlinux.org> | 2013-03-10 22:51:11 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2013-03-14 11:47:11 +1000 |
commit | 62f828014f17596cf8fb5cd2ea0c34cb754f75cb (patch) | |
tree | ba9ec71569d28177af771dc535179f23eb22cd66 /src/pacman | |
parent | d35a7fb6f36509a53e8b36d4eca03cef9d2c20db (diff) |
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 <dan@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman')
-rw-r--r-- | src/pacman/conf.c | 9 |
1 files changed, 9 insertions, 0 deletions
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 <errno.h> #include <glob.h> #include <limits.h> +#include <locale.h> /* setlocale */ #include <fcntl.h> /* open */ #include <stdlib.h> #include <stdio.h> @@ -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"), |