aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/config
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2015-10-01 12:23:39 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2015-10-01 12:23:39 +0100
commitf14decafae0d1771e16498e693e7bf2f7058e88e (patch)
treea019470ff02af16e5d85abeda9ad9e5dc945f92f /libstdc++-v3/config
parentaabef2de2f99d4a67840480eddf224ca1b43320e (diff)
downloadgcc-f14decafae0d1771e16498e693e7bf2f7058e88e.zip
gcc-f14decafae0d1771e16498e693e7bf2f7058e88e.tar.gz
gcc-f14decafae0d1771e16498e693e7bf2f7058e88e.tar.bz2
Save-and-restore errno more carefully in libstdc++
* doc/xml/manual/diagnostics.xml: Document use of errno. * doc/html/*: Regenerate. * config/locale/generic/c_locale.cc (_Save_errno): New helper. (__convert_to_v): Use _Save_errno. * include/ext/string_conversions.h (__stoa): Only restore errno when it isn't set to non-zero. From-SVN: r228328
Diffstat (limited to 'libstdc++-v3/config')
-rw-r--r--libstdc++-v3/config/locale/generic/c_locale.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/libstdc++-v3/config/locale/generic/c_locale.cc b/libstdc++-v3/config/locale/generic/c_locale.cc
index 6da5f22..8dfea6b 100644
--- a/libstdc++-v3/config/locale/generic/c_locale.cc
+++ b/libstdc++-v3/config/locale/generic/c_locale.cc
@@ -44,6 +44,16 @@ namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+ namespace
+ {
+ struct _Save_errno
+ {
+ _Save_errno() : _M_errno(errno) { errno = 0; }
+ ~_Save_errno() { if (errno == 0) errno = _M_errno; }
+ int _M_errno;
+ };
+ }
+
template<>
void
__convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
@@ -59,7 +69,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool __overflow = false;
#if !__FLT_HAS_INFINITY__
- errno = 0;
+ const _Save_errno __save_errno;
#endif
#ifdef _GLIBCXX_HAVE_STRTOF
@@ -123,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
char* __sanity;
#if !__DBL_HAS_INFINITY__
- errno = 0;
+ const _Save_errno __save_errno;
#endif
__v = strtod(__s, &__sanity);
@@ -167,7 +177,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
setlocale(LC_ALL, "C");
#if !__LDBL_HAS_INFINITY__
- errno = 0;
+ const _Save_errno __save_errno;
#endif
#if defined(_GLIBCXX_HAVE_STRTOLD) && !defined(_GLIBCXX_HAVE_BROKEN_STRTOLD)