From: Jim Meyering Date: Sat, 29 Nov 2003 11:55:52 +0000 (+0000) Subject: (c_strtod): Save and restore original LC_NUMERIC setting, X-Git-Tag: v5.1.0~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b91ac83e675ed779664fbe7fe8f0062a953aaf19;p=thirdparty%2Fcoreutils.git (c_strtod): Save and restore original LC_NUMERIC setting, in case it was different from the environment-derived value. Patch by Paul Eggert. --- diff --git a/lib/c-strtod.c b/lib/c-strtod.c index b3fac020a9..b3ce2b43a6 100644 --- a/lib/c-strtod.c +++ b/lib/c-strtod.c @@ -27,8 +27,21 @@ double c_strtod (char const *nptr, char **endptr) { double r; - setlocale (LC_NUMERIC, "C"); + char *saved_locale = setlocale (LC_NUMERIC, NULL); + + if (saved_locale) + { + saved_locale = xstrdup (saved_locale); + setlocale (LC_NUMERIC, "C"); + } + r = strtod (nptr, endptr); - setlocale (LC_NUMERIC, ""); + + if (saved_locale) + { + setlocale (LC_NUMERIC, saved_locale); + free (saved_locale); + } + return r; }