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 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
37 // ISO C++ 14882: 22.8 Standard locale categories.
40 // Written by Benjamin Kosnik <bkoz@redhat.com>
45 #pragma GCC system_header
47 #include <cstring> // get std::strlen
48 #include <cstdio> // get std::vsnprintf or std::vsprintf
50 #include <langinfo.h> // For codecvt
51 #include <iconv.h> // For codecvt using iconv, iconv_t
52 #include <libintl.h> // For messages
55 #define _GLIBCXX_C_LOCALE_GNU 1
57 #define _GLIBCXX_NUM_CATEGORIES 6
59 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
60 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
62 extern "C" __typeof(uselocale) __uselocale;
64 _GLIBCXX_END_NAMESPACE
67 _GLIBCXX_BEGIN_NAMESPACE(std)
69 typedef __locale_t __c_locale;
71 // Convert numeric value of type double and long double to string and
72 // return length of string. If vsnprintf is available use it, otherwise
73 // fall back to the unsafe vsprintf which, in general, can be dangerous
74 // and should be avoided.
76 __convert_from_v(const __c_locale& __cloc __attribute__ ((__unused__)),
78 const int __size __attribute__ ((__unused__)),
79 const char* __fmt, ...)
81 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
82 __c_locale __old = __gnu_cxx::__uselocale(__cloc);
84 char* __old = std::setlocale(LC_ALL, NULL);
85 char* __sav = new char[std::strlen(__old) + 1];
86 std::strcpy(__sav, __old);
87 std::setlocale(LC_ALL, "C");
91 va_start(__args, __fmt);
93 #ifdef _GLIBCXX_USE_C99
94 const int __ret = std::vsnprintf(__out, __size, __fmt, __args);
96 const int __ret = std::vsprintf(__out, __fmt, __args);
101 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
102 __gnu_cxx::__uselocale(__old);
104 std::setlocale(LC_ALL, __sav);
110 _GLIBCXX_END_NAMESPACE