]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/config/locale/generic/c_locale.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / config / locale / generic / c_locale.h
1 // Wrapper for underlying C-language localization -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 2, 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 // 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,
20 // USA.
21
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.
30
31 /** @file c++locale.h
32  *  This is an internal header file, included by other library headers.
33  *  You should not attempt to use it directly.
34  */
35
36 //
37 // ISO C++ 14882: 22.8  Standard locale categories.
38 //
39
40 // Written by Benjamin Kosnik <bkoz@redhat.com>
41
42 #ifndef _GLIBCXX_CXX_LOCALE_H
43 #define _GLIBCXX_CXX_LOCALE_H 1
44
45 #pragma GCC system_header
46
47 #include <clocale>
48 #include <cstddef>
49
50 #define _GLIBCXX_NUM_CATEGORIES 0
51
52 _GLIBCXX_BEGIN_NAMESPACE(std)
53
54   typedef int*                  __c_locale;
55
56   // Convert numeric value of type double and long double to string and
57   // return length of string.  If vsnprintf is available use it, otherwise
58   // fall back to the unsafe vsprintf which, in general, can be dangerous
59   // and should be avoided.
60   inline int
61   __convert_from_v(const __c_locale&, char* __out, 
62                    const int __size __attribute__((__unused__)),
63                    const char* __fmt, ...)
64   {
65     char* __old = std::setlocale(LC_NUMERIC, NULL);
66     char* __sav = NULL;
67     if (__builtin_strcmp(__old, "C"))
68       {
69         const size_t __len = __builtin_strlen(__old) + 1;
70         __sav = new char[__len];
71         __builtin_memcpy(__sav, __old, __len);
72         std::setlocale(LC_NUMERIC, "C");
73       }
74
75     __builtin_va_list __args;
76     __builtin_va_start(__args, __fmt);
77
78 #ifdef _GLIBCXX_USE_C99
79     const int __ret = __builtin_vsnprintf(__out, __size, __fmt, __args);
80 #else
81     const int __ret = __builtin_vsprintf(__out, __fmt, __args);
82 #endif
83
84     __builtin_va_end(__args);
85
86     if (__sav)
87       {
88         std::setlocale(LC_NUMERIC, __sav);
89         delete [] __sav;
90       }
91     return __ret;
92   }
93
94 _GLIBCXX_END_NAMESPACE
95
96 #endif