163aace61Smrg // localization implementation details, DragonFly version -*- C++ -*-
263aace61Smrg
32f055536Smrg // Copyright (C) 2001-2020 Free Software Foundation, Inc.
463aace61Smrg //
563aace61Smrg // This file is part of the GNU ISO C++ Library. This library is free
663aace61Smrg // software; you can redistribute it and/or modify it under the
763aace61Smrg // terms of the GNU General Public License as published by the
863aace61Smrg // Free Software Foundation; either version 3, or (at your option)
963aace61Smrg // any later version.
1063aace61Smrg
1163aace61Smrg // This library is distributed in the hope that it will be useful,
1263aace61Smrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
1363aace61Smrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1463aace61Smrg // GNU General Public License for more details.
1563aace61Smrg
1663aace61Smrg // Under Section 7 of GPL version 3, you are granted additional
1763aace61Smrg // permissions described in the GCC Runtime Library Exception, version
1863aace61Smrg // 3.1, as published by the Free Software Foundation.
1963aace61Smrg
2063aace61Smrg // You should have received a copy of the GNU General Public License and
2163aace61Smrg // a copy of the GCC Runtime Library Exception along with this program;
2263aace61Smrg // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2363aace61Smrg // <http://www.gnu.org/licenses/>.
2463aace61Smrg
2563aace61Smrg /** @file bits/c++locale.h
2663aace61Smrg * This is an internal header file, included by other library headers.
2763aace61Smrg * Do not attempt to use it directly. @headername{locale}
2863aace61Smrg */
2963aace61Smrg
3063aace61Smrg //
3163aace61Smrg // ISO C++ 14882: 22.8 Standard locale categories.
3263aace61Smrg //
3363aace61Smrg
3463aace61Smrg // Written by Benjamin Kosnik <bkoz@redhat.com>
3563aace61Smrg // Modified for DragonFly by John Marino <gnugcc@marino.st>
36*e77b3a7cSmrg // Modified for NetBSD by Christos Zoulas <christos@zoulas.com> and
37*e77b3a7cSmrg // matthew green <mrg@eterna.com.au>
3863aace61Smrg
3963aace61Smrg #ifndef _GLIBCXX_CXX_LOCALE_H
4063aace61Smrg #define _GLIBCXX_CXX_LOCALE_H 1
4163aace61Smrg
4263aace61Smrg #pragma GCC system_header
4363aace61Smrg
4463aace61Smrg #include <clocale>
452d664adbSchristos #ifndef __NetBSD__
4663aace61Smrg #include <xlocale.h>
472d664adbSchristos #else
482d664adbSchristos #include <cstdio>
492d664adbSchristos #endif
5063aace61Smrg
5163aace61Smrg #define _GLIBCXX_NUM_CATEGORIES 0
5263aace61Smrg
_GLIBCXX_VISIBILITY(default)5363aace61Smrg namespace std _GLIBCXX_VISIBILITY(default)
5463aace61Smrg {
5563aace61Smrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
5663aace61Smrg
5763aace61Smrg typedef int* __c_locale;
5863aace61Smrg
59*e77b3a7cSmrg #ifndef __NetBSD__
6063aace61Smrg // Convert numeric value of type double and long double to string and
6163aace61Smrg // return length of string. If vsnprintf is available use it, otherwise
6263aace61Smrg // fall back to the unsafe vsprintf which, in general, can be dangerous
6363aace61Smrg // and should be avoided.
6463aace61Smrg inline int
6563aace61Smrg __convert_from_v(const __c_locale& __cloc, char* __out,
6663aace61Smrg const int __size __attribute__ ((__unused__)),
6763aace61Smrg const char* __fmt, ...)
6863aace61Smrg {
6963aace61Smrg __c_locale __old = (__c_locale)uselocale((locale_t)__cloc);
7063aace61Smrg
7163aace61Smrg __builtin_va_list __args;
7263aace61Smrg __builtin_va_start(__args, __fmt);
7363aace61Smrg
7463aace61Smrg #if _GLIBCXX_USE_C99_STDIO
7563aace61Smrg const int __ret = __builtin_vsnprintf(__out, __size, __fmt, __args);
7663aace61Smrg #else
7763aace61Smrg const int __ret = __builtin_vsprintf(__out, __fmt, __args);
7863aace61Smrg #endif
7963aace61Smrg
8063aace61Smrg __builtin_va_end(__args);
8163aace61Smrg
82*e77b3a7cSmrg uselocale((locale_t)__old);
8363aace61Smrg return __ret;
8463aace61Smrg }
85*e77b3a7cSmrg #else
86*e77b3a7cSmrg // NetBSD backend requires vasprintf_l() which may not be visible in
87*e77b3a7cSmrg // all complation environments (eg, _XOPEN_SOURCE=600) so the backend
88*e77b3a7cSmrg // lives in the library code, instead of this header.
89*e77b3a7cSmrg int
90*e77b3a7cSmrg __convert_from_v(const __c_locale& __cloc, char* __out,
91*e77b3a7cSmrg const int __size __attribute__ ((__unused__)),
92*e77b3a7cSmrg const char* __fmt, ...);
93*e77b3a7cSmrg #endif
9463aace61Smrg
9563aace61Smrg _GLIBCXX_END_NAMESPACE_VERSION
9663aace61Smrg } // namespace
9763aace61Smrg
9863aace61Smrg #endif
99