summaryrefslogtreecommitdiff
path: root/libstdc++-v3/config/locale/generic/c_locale.h
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-12 23:24:22 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-12 23:24:22 +0000
commit6e4fc2df81dc22de969606e9ae7c08eb3a47f9d5 (patch)
tree425803261bfa01dea32ec1fe7aaf9b62551f4d99 /libstdc++-v3/config/locale/generic/c_locale.h
parent8d7dd4374140926aa91dc08673078b720ca5be7e (diff)
downloadgcc-6e4fc2df81dc22de969606e9ae7c08eb3a47f9d5.tar.gz
2006-06-12 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/26970 * config/locale/gnu/c_locale.h (__convert_from_v<>): Change to variadic function, instead of template function. * config/locale/generic/c_locale.h (__convert_from_v<>): Likewise. * include/bits/locale_facets.tcc (num_put<>::_M_insert_float): Adjust. (money_put<>::do_put(long double)): Likewise. * src/locale-misc-inst.cc: Remove. * src/Makefile.am: Adjust. * src/Makefile.in: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114591 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/config/locale/generic/c_locale.h')
-rw-r--r--libstdc++-v3/config/locale/generic/c_locale.h65
1 files changed, 35 insertions, 30 deletions
diff --git a/libstdc++-v3/config/locale/generic/c_locale.h b/libstdc++-v3/config/locale/generic/c_locale.h
index d6e2f65e06e..d71af1d0a16 100644
--- a/libstdc++-v3/config/locale/generic/c_locale.h
+++ b/libstdc++-v3/config/locale/generic/c_locale.h
@@ -1,6 +1,7 @@
// Wrapper for underlying C-language localization -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -40,7 +41,8 @@
#include <clocale>
#include <cstring> // get std::strlen
-#include <cstdio> // get std::snprintf or std::sprintf
+#include <cstdio> // get std::vsnprintf or std::vsprintf
+#include <cstdarg>
#define _GLIBCXX_NUM_CATEGORIES 0
@@ -48,39 +50,42 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typedef int* __c_locale;
- // Convert numeric value of type _Tv to string and return length of
- // string. If snprintf is available use it, otherwise fall back to
- // the unsafe sprintf which, in general, can be dangerous and should
- // be avoided.
- template<typename _Tv>
- int
- __convert_from_v(char* __out,
- const int __size __attribute__((__unused__)),
- const char* __fmt,
- _Tv __v, const __c_locale&, int __prec)
- {
- char* __old = std::setlocale(LC_NUMERIC, NULL);
- char* __sav = NULL;
- if (std::strcmp(__old, "C"))
- {
- __sav = new char[std::strlen(__old) + 1];
- std::strcpy(__sav, __old);
- std::setlocale(LC_NUMERIC, "C");
- }
+ // Convert numeric value of type double and long double to string and
+ // return length of string. If vsnprintf is available use it, otherwise
+ // fall back to the unsafe vsprintf which, in general, can be dangerous
+ // and should be avoided.
+ inline int
+ __convert_from_v(const __c_locale&, char* __out,
+ const int __size __attribute__((__unused__)),
+ const char* __fmt, ...)
+ {
+ char* __old = std::setlocale(LC_NUMERIC, NULL);
+ char* __sav = NULL;
+ if (std::strcmp(__old, "C"))
+ {
+ __sav = new char[std::strlen(__old) + 1];
+ std::strcpy(__sav, __old);
+ std::setlocale(LC_NUMERIC, "C");
+ }
+
+ va_list __args;
+ va_start(__args, __fmt);
#ifdef _GLIBCXX_USE_C99
- const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
+ const int __ret = std::vsnprintf(__out, __size, __fmt, __args);
#else
- const int __ret = std::sprintf(__out, __fmt, __prec, __v);
+ const int __ret = std::vsprintf(__out, __fmt, __args);
#endif
+
+ va_end(__args);
- if (__sav)
- {
- std::setlocale(LC_NUMERIC, __sav);
- delete [] __sav;
- }
- return __ret;
- }
+ if (__sav)
+ {
+ std::setlocale(LC_NUMERIC, __sav);
+ delete [] __sav;
+ }
+ return __ret;
+ }
_GLIBCXX_END_NAMESPACE