#include <cerrno> // For errno
#include <cmath> // For isinf, finite, finitef, fabs
#include <cstdlib> // For strof, strtold
#include <locale>
#ifdef _GLIBCXX_HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
namespace std
{
template<>
void
__convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
const __c_locale&)
{
if (!(__err & ios_base::failbit))
{
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
errno = 0;
#if defined(_GLIBCXX_HAVE_STRTOF)
float __f = strtof(__s, &__sanity);
#else
double __d = strtod(__s, &__sanity);
float __f = static_cast<float>(__d);
#ifdef _GLIBCXX_HAVE_FINITEF
if (!finitef (__f))
errno = ERANGE;
#elif defined (_GLIBCXX_HAVE_FINITE)
if (!finite (static_cast<double> (__f)))
errno = ERANGE;
#elif defined (_GLIBCXX_HAVE_ISINF)
if (isinf (static_cast<double> (__f)))
errno = ERANGE;
#else
if (fabs(__d) > numeric_limits<float>::max())
errno = ERANGE;
#endif
#endif
if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
}
template<>
void
__convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
const __c_locale&)
{
if (!(__err & ios_base::failbit))
{
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
errno = 0;
double __d = strtod(__s, &__sanity);
if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
}
template<>
void
__convert_to_v(const char* __s, long double& __v,
ios_base::iostate& __err, const __c_locale&)
{
if (!(__err & ios_base::failbit))
{
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
#if defined(_GLIBCXX_HAVE_STRTOLD)
char* __sanity;
errno = 0;
long double __ld = strtold(__s, &__sanity);
if (__sanity != __s && errno != ERANGE)
__v = __ld;
#else
typedef char_traits<char>::int_type int_type;
long double __ld;
errno = 0;
int __p = sscanf(__s, "%Lf", &__ld);
if (__p && static_cast<int_type>(__p) != char_traits<char>::eof()
&& errno != ERANGE)
__v = __ld;
#endif
else
__err |= ios_base::failbit;
setlocale(LC_ALL, __old);
free(__old);
}
}
void
locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
__c_locale)
{
__cloc = NULL;
if (strcmp(__s, "C"))
__throw_runtime_error(__N("locale::facet::_S_create_c_locale "
"name not valid"));
}
void
locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
{ __cloc = NULL; }
__c_locale
locale::facet::_S_clone_c_locale(__c_locale&)
{ return __c_locale(); }
}
namespace __gnu_cxx
{
const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
{
"LC_CTYPE",
"LC_NUMERIC",
"LC_TIME",
"LC_COLLATE",
"LC_MONETARY",
"LC_MESSAGES"
};
}
namespace std
{
const char* const* const locale::_S_categories = __gnu_cxx::category_names;
}