1 // Wrapper for underlying C-language localization -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 22.8 Standard locale categories.
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
37 #include <cerrno> // For errno
41 #include <bits/c++locale_internal.h>
43 _GLIBCXX_BEGIN_NAMESPACE(std)
47 __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
48 const __c_locale& __cloc)
52 float __f = __strtof_l(__s, &__sanity, __cloc);
53 if (__sanity != __s && errno != ERANGE)
56 __err |= ios_base::failbit;
61 __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
62 const __c_locale& __cloc)
66 double __d = __strtod_l(__s, &__sanity, __cloc);
67 if (__sanity != __s && errno != ERANGE)
70 __err |= ios_base::failbit;
75 __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
76 const __c_locale& __cloc)
80 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
81 // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
83 long double __ld = strtold_l(__s, &__sanity, __cloc);
85 long double __ld = __strtold_l(__s, &__sanity, __cloc);
87 if (__sanity != __s && errno != ERANGE)
90 __err |= ios_base::failbit;
94 locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
97 __cloc = __newlocale(1 << LC_ALL, __s, __old);
100 // This named locale is not supported by the underlying OS.
101 __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
107 locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
109 if (__cloc && _S_get_c_locale() != __cloc)
110 __freelocale(__cloc);
114 locale::facet::_S_clone_c_locale(__c_locale& __cloc)
115 { return __duplocale(__cloc); }
117 _GLIBCXX_END_NAMESPACE
119 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
121 const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
137 _GLIBCXX_END_NAMESPACE
139 _GLIBCXX_BEGIN_NAMESPACE(std)
141 const char* const* const locale::_S_categories = __gnu_cxx::category_names;
143 _GLIBCXX_END_NAMESPACE
145 // XXX GLIBCXX_ABI Deprecated
146 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
147 #define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
148 extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
149 _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
150 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT