]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/config/locale/dragonfly/c_locale.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / dragonfly / c_locale.cc
CommitLineData
418255b1 1// localization implementation details, DragonFly version -*- C++ -*-
463553db 2
fbd26352 3// Copyright (C) 2014-2019 Free Software Foundation, Inc.
463553db 4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25//
26// ISO C++ 14882: 22.8 Standard locale categories.
27//
28
29// Written by Benjamin Kosnik <bkoz@redhat.com>
418255b1 30// Modified for DragonFly by John Marino <gnugcc@marino.st>
463553db 31
418255b1 32#include <cstdlib>
463553db 33#include <locale>
418255b1 34#include <stdexcept>
463553db 35#include <limits>
418255b1 36#include <langinfo.h>
37#include <xlocale.h>
463553db 38
39namespace std _GLIBCXX_VISIBILITY(default)
40{
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
42
43 template<>
44 void
45 __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
418255b1 46 const __c_locale& __cloc) throw()
463553db 47 {
463553db 48 char* __sanity;
418255b1 49 __v = strtof_l(__s, &__sanity, (locale_t)__cloc);
463553db 50
51 // _GLIBCXX_RESOLVE_LIB_DEFECTS
52 // 23. Num_get overflow result.
53 if (__sanity == __s || *__sanity != '\0')
54 {
55 __v = 0.0f;
56 __err = ios_base::failbit;
57 }
418255b1 58 else if (__v == numeric_limits<float>::infinity())
463553db 59 {
418255b1 60 __v = numeric_limits<float>::max();
61 __err = ios_base::failbit;
62 }
63 else if (__v == -numeric_limits<float>::infinity())
64 {
65 __v = -numeric_limits<float>::max();
463553db 66 __err = ios_base::failbit;
67 }
463553db 68 }
69
70 template<>
71 void
72 __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
418255b1 73 const __c_locale& __cloc) throw()
463553db 74 {
463553db 75 char* __sanity;
418255b1 76 __v = strtod_l(__s, &__sanity, (locale_t)__cloc);
463553db 77
78 // _GLIBCXX_RESOLVE_LIB_DEFECTS
79 // 23. Num_get overflow result.
80 if (__sanity == __s || *__sanity != '\0')
81 {
82 __v = 0.0;
83 __err = ios_base::failbit;
84 }
418255b1 85 else if (__v == numeric_limits<double>::infinity())
463553db 86 {
418255b1 87 __v = numeric_limits<double>::max();
88 __err = ios_base::failbit;
89 }
90 else if (__v == -numeric_limits<double>::infinity())
91 {
92 __v = -numeric_limits<double>::max();
463553db 93 __err = ios_base::failbit;
94 }
463553db 95 }
96
97 template<>
98 void
418255b1 99 __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
100 const __c_locale& __cloc) throw()
463553db 101 {
463553db 102 char* __sanity;
418255b1 103 __v = strtold_l(__s, &__sanity, (locale_t)__cloc);
463553db 104
105 // _GLIBCXX_RESOLVE_LIB_DEFECTS
106 // 23. Num_get overflow result.
107 if (__sanity == __s || *__sanity != '\0')
463553db 108 {
109 __v = 0.0l;
110 __err = ios_base::failbit;
111 }
418255b1 112 else if (__v == numeric_limits<long double>::infinity())
463553db 113 {
418255b1 114 __v = numeric_limits<long double>::max();
115 __err = ios_base::failbit;
116 }
117 else if (__v == -numeric_limits<long double>::infinity())
118 {
119 __v = -numeric_limits<long double>::max();
463553db 120 __err = ios_base::failbit;
121 }
463553db 122 }
123
463553db 124 void
125 locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
418255b1 126 __c_locale __old)
463553db 127 {
418255b1 128 __cloc = (__c_locale)newlocale(LC_ALL_MASK, __s, (locale_t)__old);
129 if (!__cloc)
130 {
131 // This named locale is not supported by the underlying OS.
132 __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
133 "name not valid"));
134 }
463553db 135 }
136
137 void
138 locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
418255b1 139 {
140 if (__cloc && _S_get_c_locale() != __cloc)
141 freelocale((locale_t)__cloc);
142 }
463553db 143
144 __c_locale
418255b1 145 locale::facet::_S_clone_c_locale(__c_locale& __cloc) throw()
146 { return (__c_locale)duplocale((locale_t)__cloc); }
463553db 147
148 __c_locale
418255b1 149 locale::facet::_S_lc_ctype_c_locale(__c_locale __cloc, const char* __s)
150 {
151 __c_locale __dup = (__c_locale)duplocale((locale_t)__cloc);
152 if (__dup == __c_locale(0))
153 __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
154 "duplocale error"));
155 __c_locale __changed = (__c_locale)newlocale(LC_CTYPE_MASK, __s,
156 (locale_t)__dup);
157 if (__changed == __c_locale(0))
158 {
159 freelocale((locale_t)__dup);
160 __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
161 "newlocale error"));
162 }
163 return __changed;
164 }
463553db 165
166_GLIBCXX_END_NAMESPACE_VERSION
167} // namespace
168
169namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
170{
171_GLIBCXX_BEGIN_NAMESPACE_VERSION
172
173 const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
174 {
175 "LC_CTYPE",
176 "LC_NUMERIC",
177 "LC_TIME",
178 "LC_COLLATE",
179 "LC_MONETARY",
180 "LC_MESSAGES"
181 };
182
183_GLIBCXX_END_NAMESPACE_VERSION
184} // namespace
185
186namespace std _GLIBCXX_VISIBILITY(default)
187{
188_GLIBCXX_BEGIN_NAMESPACE_VERSION
189
190 const char* const* const locale::_S_categories = __gnu_cxx::category_names;
191
192_GLIBCXX_END_NAMESPACE_VERSION
193} // namespace
194
195// XXX GLIBCXX_ABI Deprecated
196#ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
197#define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
198 extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
418255b1 199_GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
463553db 200#endif // _GLIBCXX_LONG_DOUBLE_COMPAT