From: Bruno Haible Date: Wed, 21 Jan 2009 22:35:43 +0000 (+0100) Subject: Improve error handling of c_strtod. X-Git-Tag: v0.1~6416 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=39857ab5806b8ceffaf5aab75fb20a2e872268a9;p=gnulib.git Improve error handling of c_strtod. --- diff --git a/ChangeLog b/ChangeLog index 4dd6650ec..5dd2451da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ 2009-01-21 Bruno Haible + + * lib/c-strtod.c: Include errno.h. + (C_STRTOD): Check against NULL return from newlocale. Preserve errno + value from STRTOD_L and STRTOD. + +2009-01-21 Bruno Haible and Jim Meyering nanosleep: skip configure test (fail it) for apple universal builds diff --git a/lib/c-strtod.c b/lib/c-strtod.c index 95624ccc1..0f97528a8 100644 --- a/lib/c-strtod.c +++ b/lib/c-strtod.c @@ -1,6 +1,6 @@ /* Convert string to double, using the C locale. - Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2006, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "c-strtod.h" +#include #include #include @@ -50,9 +51,18 @@ C_STRTOD (char const *nptr, char **endptr) #ifdef LC_ALL_MASK - locale_t c_locale = newlocale (LC_ALL_MASK, "C", 0); + locale_t c_locale; + int saved_errno; + + c_locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0); + if (!c_locale) + return 0; /* errno is set here */ + r = STRTOD_L (nptr, endptr, c_locale); + + saved_errno = errno; freelocale (c_locale); + errno = saved_errno; #else @@ -68,8 +78,11 @@ C_STRTOD (char const *nptr, char **endptr) if (saved_locale) { + int saved_errno = errno; + setlocale (LC_NUMERIC, saved_locale); free (saved_locale); + errno = saved_errno; } #endif