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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [config/] [locale/] [gnu/] [c_locale.h] - Blame information for rev 20

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 20 jlechner
// Wrapper for underlying C-language localization -*- C++ -*-
2
 
3
// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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 2, 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
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// As a special exception, you may use this file as part of a free software
22
// library without restriction.  Specifically, if other files instantiate
23
// templates or use macros or inline functions from this file, or you compile
24
// this file and link it with other files to produce an executable, this
25
// file does not by itself cause the resulting executable to be covered by
26
// the GNU General Public License.  This exception does not however
27
// invalidate any other reasons why the executable file might be covered by
28
// the GNU General Public License.
29
 
30
//
31
// ISO C++ 14882: 22.8  Standard locale categories.
32
//
33
 
34
// Written by Benjamin Kosnik <bkoz@redhat.com>
35
 
36
#ifndef _C_LOCALE_H
37
#define _C_LOCALE_H 1
38
 
39
#pragma GCC system_header
40
 
41
#include <cstring>              // get std::strlen
42
#include <cstdio>               // get std::snprintf or std::sprintf
43
#include <clocale>
44
#include <langinfo.h>           // For codecvt
45
#include <iconv.h>              // For codecvt using iconv, iconv_t
46
#include <libintl.h>            // For messages
47
 
48
#define _GLIBCXX_C_LOCALE_GNU 1
49
 
50
#define _GLIBCXX_NUM_CATEGORIES 6
51
 
52
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
53
namespace __gnu_cxx
54
{
55
  extern "C" __typeof(uselocale) __uselocale;
56
}
57
#endif
58
 
59
namespace std
60
{
61
  typedef __locale_t            __c_locale;
62
 
63
  // Convert numeric value of type _Tv to string and return length of
64
  // string.  If snprintf is available use it, otherwise fall back to
65
  // the unsafe sprintf which, in general, can be dangerous and should
66
  // be avoided.
67
  template<typename _Tv>
68
    int
69
    __convert_from_v(char* __out,
70
                     const int __size __attribute__ ((__unused__)),
71
                     const char* __fmt,
72
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
73
                     _Tv __v, const __c_locale& __cloc, int __prec)
74
    {
75
      __c_locale __old = __gnu_cxx::__uselocale(__cloc);
76
#else
77
                     _Tv __v, const __c_locale&, int __prec)
78
    {
79
      char* __old = std::setlocale(LC_ALL, NULL);
80
      char* __sav = new char[std::strlen(__old) + 1];
81
      std::strcpy(__sav, __old);
82
      std::setlocale(LC_ALL, "C");
83
#endif
84
 
85
#ifdef _GLIBCXX_USE_C99
86
      const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
87
#else
88
      const int __ret = std::sprintf(__out, __fmt, __prec, __v);
89
#endif
90
 
91
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
92
      __gnu_cxx::__uselocale(__old);
93
#else
94
      std::setlocale(LC_ALL, __sav);
95
      delete [] __sav;
96
#endif
97
      return __ret;
98
    }
99
}
100
 
101
#endif

powered by: WebSVN 2.1.0

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