OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-dev/] [fsf-gcc-snapshot-1-mar-12/] [or1k-gcc/] [libstdc++-v3/] [config/] [locale/] [gnu/] [c_locale.cc] - Blame information for rev 783

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// Wrapper for underlying C-language localization -*- C++ -*-
2
 
3
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4
// Free Software Foundation, Inc.
5
//
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 3, or (at your option)
10
// any later version.
11
 
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.
16
 
17
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// <http://www.gnu.org/licenses/>.
25
 
26
//
27
// ISO C++ 14882: 22.8  Standard locale categories.
28
//
29
 
30
// Written by Benjamin Kosnik <bkoz@redhat.com>
31
 
32
#include <locale>
33
#include <stdexcept>
34
#include <limits>
35
#include <langinfo.h>
36
#include <bits/c++locale_internal.h>
37
 
38
namespace std _GLIBCXX_VISIBILITY(default)
39
{
40
_GLIBCXX_BEGIN_NAMESPACE_VERSION
41
 
42
  template<>
43
    void
44
    __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
45
                   const __c_locale& __cloc) throw()
46
    {
47
      char* __sanity;
48
      __v = __strtof_l(__s, &__sanity, __cloc);
49
 
50
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
51
      // 23. Num_get overflow result.
52
      if (__sanity == __s || *__sanity != '\0')
53
        {
54
          __v = 0.0f;
55
          __err = ios_base::failbit;
56
        }
57
      else if (__v == numeric_limits<float>::infinity())
58
        {
59
          __v = numeric_limits<float>::max();
60
          __err = ios_base::failbit;
61
        }
62
      else if (__v == -numeric_limits<float>::infinity())
63
        {
64
          __v = -numeric_limits<float>::max();
65
          __err = ios_base::failbit;
66
        }
67
    }
68
 
69
  template<>
70
    void
71
    __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
72
                   const __c_locale& __cloc) throw()
73
    {
74
      char* __sanity;
75
      __v = __strtod_l(__s, &__sanity, __cloc);
76
 
77
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
78
      // 23. Num_get overflow result.
79
      if (__sanity == __s || *__sanity != '\0')
80
        {
81
          __v = 0.0;
82
          __err = ios_base::failbit;
83
        }
84
      else if (__v == numeric_limits<double>::infinity())
85
        {
86
          __v = numeric_limits<double>::max();
87
          __err = ios_base::failbit;
88
        }
89
      else if (__v == -numeric_limits<double>::infinity())
90
        {
91
          __v = -numeric_limits<double>::max();
92
          __err = ios_base::failbit;
93
        }
94
    }
95
 
96
  template<>
97
    void
98
    __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
99
                   const __c_locale& __cloc) throw()
100
    {
101
      char* __sanity;
102
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
103
      // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
104
      // glibc versions.
105
      __v = strtold_l(__s, &__sanity, __cloc);
106
#else
107
      __v = __strtold_l(__s, &__sanity, __cloc);
108
#endif
109
 
110
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
111
      // 23. Num_get overflow result.
112
      if (__sanity == __s || *__sanity != '\0')
113
        {
114
          __v = 0.0l;
115
          __err = ios_base::failbit;
116
        }
117
      else if (__v == numeric_limits<long double>::infinity())
118
        {
119
          __v = numeric_limits<long double>::max();
120
          __err = ios_base::failbit;
121
        }
122
      else if (__v == -numeric_limits<long double>::infinity())
123
        {
124
          __v = -numeric_limits<long double>::max();
125
          __err = ios_base::failbit;
126
        }
127
    }
128
 
129
  void
130
  locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
131
                                    __c_locale __old)
132
  {
133
    __cloc = __newlocale(1 << LC_ALL, __s, __old);
134
    if (!__cloc)
135
      {
136
        // This named locale is not supported by the underlying OS.
137
        __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
138
                                  "name not valid"));
139
      }
140
  }
141
 
142
  void
143
  locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
144
  {
145
    if (__cloc && _S_get_c_locale() != __cloc)
146
      __freelocale(__cloc);
147
  }
148
 
149
  __c_locale
150
  locale::facet::_S_clone_c_locale(__c_locale& __cloc) throw()
151
  { return __duplocale(__cloc); }
152
 
153
  __c_locale
154
  locale::facet::_S_lc_ctype_c_locale(__c_locale __cloc, const char* __s)
155
  {
156
    __c_locale __dup = __duplocale(__cloc);
157
    if (__dup == __c_locale(0))
158
      __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
159
                                "duplocale error"));
160
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
161
    __c_locale __changed = __newlocale(LC_CTYPE_MASK, __s, __dup);
162
#else
163
    __c_locale __changed = __newlocale(1 << LC_CTYPE, __s, __dup);
164
#endif
165
    if (__changed == __c_locale(0))
166
      {
167
        __freelocale(__dup);
168
        __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
169
                                  "newlocale error"));
170
      }
171
    return __changed;
172
  }
173
 
174
_GLIBCXX_END_NAMESPACE_VERSION
175
} // namespace
176
 
177
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
178
{
179
_GLIBCXX_BEGIN_NAMESPACE_VERSION
180
 
181
  const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
182
    {
183
      "LC_CTYPE",
184
      "LC_NUMERIC",
185
      "LC_TIME",
186
      "LC_COLLATE",
187
      "LC_MONETARY",
188
      "LC_MESSAGES",
189
      "LC_PAPER",
190
      "LC_NAME",
191
      "LC_ADDRESS",
192
      "LC_TELEPHONE",
193
      "LC_MEASUREMENT",
194
      "LC_IDENTIFICATION"
195
    };
196
 
197
_GLIBCXX_END_NAMESPACE_VERSION
198
} // namespace
199
 
200
namespace std _GLIBCXX_VISIBILITY(default)
201
{
202
_GLIBCXX_BEGIN_NAMESPACE_VERSION
203
 
204
  const char* const* const locale::_S_categories = __gnu_cxx::category_names;
205
 
206
_GLIBCXX_END_NAMESPACE_VERSION
207
} // namespace
208
 
209
// XXX GLIBCXX_ABI Deprecated
210
#ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
211
#define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
212
  extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
213
_GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
214
#endif // _GLIBCXX_LONG_DOUBLE_COMPAT

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.