// Wrapper for underlying C-language localization -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// Written by Benjamin Kosnik <bkoz@redhat.com>
-#include <cerrno> // For errno
#include <cmath> // For isinf, finite, finitef, fabs
#include <cstdlib> // For strof, strtold
#include <locale>
const __c_locale&)
{
// Assumes __s formatted for "C" locale.
- errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
float __f = static_cast<float>(__d);
#ifdef _GLIBCXX_HAVE_FINITEF
if (!finitef (__f))
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#elif defined (_GLIBCXX_HAVE_FINITE)
if (!finite (static_cast<double> (__f)))
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#elif defined (_GLIBCXX_HAVE_ISINF)
if (isinf (static_cast<double> (__f)))
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#else
if (fabs(__d) > numeric_limits<float>::max())
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#endif
#endif
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __f != __builtin_huge_valf()
+ && __f != -__builtin_huge_valf())
__v = __f;
else
__err |= ios_base::failbit;
const __c_locale&)
{
// Assumes __s formatted for "C" locale.
- errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
double __d = strtod(__s, &__sanity);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __d != __builtin_huge_val()
+ && __d != -__builtin_huge_val())
__v = __d;
else
__err |= ios_base::failbit;
ios_base::iostate& __err, const __c_locale&)
{
// Assumes __s formatted for "C" locale.
- errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
#if defined(_GLIBCXX_HAVE_STRTOLD)
char* __sanity;
long double __ld = strtold(__s, &__sanity);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __ld != __builtin_huge_vall()
+ && __ld != -__builtin_huge_vall())
__v = __ld;
#else
typedef char_traits<char>::int_type int_type;
long double __ld;
int __p = sscanf(__s, "%Lf", &__ld);
if (__p && static_cast<int_type>(__p) != char_traits<char>::eof()
- && errno != ERANGE)
+ && __ld != __builtin_huge_vall()
+ && __ld != -__builtin_huge_vall())
__v = __ld;
#endif
else
// Wrapper for underlying C-language localization -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// Written by Benjamin Kosnik <bkoz@redhat.com>
-#include <cerrno> // For errno
#include <locale>
#include <stdexcept>
#include <langinfo.h>
const __c_locale& __cloc)
{
char* __sanity;
- errno = 0;
float __f = __strtof_l(__s, &__sanity, __cloc);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __f != __builtin_huge_valf()
+ && __f != -__builtin_huge_valf())
__v = __f;
else
__err |= ios_base::failbit;
const __c_locale& __cloc)
{
char* __sanity;
- errno = 0;
double __d = __strtod_l(__s, &__sanity, __cloc);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __d != __builtin_huge_val()
+ && __d != -__builtin_huge_val())
__v = __d;
else
__err |= ios_base::failbit;
const __c_locale& __cloc)
{
char* __sanity;
- errno = 0;
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
// Prefer strtold_l, as __strtold_l isn't prototyped in more recent
// glibc versions.
#else
long double __ld = __strtold_l(__s, &__sanity, __cloc);
#endif
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __ld != __builtin_huge_vall()
+ && __ld != -__builtin_huge_vall())
__v = __ld;
else
__err |= ios_base::failbit;