]> oss.titaniummirror.com Git - msp430-gcc.git/blobdiff - libstdc++-v3/config/locale/gnu/c_locale.cc
Imported gcc-4.4.3
[msp430-gcc.git] / libstdc++-v3 / config / locale / gnu / c_locale.cc
index 188f3a2f1c1bcb60db184d6769dcfd529ce8a1e2..cd32dc03130e0719fecb26fddd2c4cbfaeddff29 100644 (file)
@@ -1,11 +1,12 @@
 // Wrapper for underlying C-language localization -*- C++ -*-
 
-// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// 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
 // terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
 // any later version.
 
 // This library is distributed in the hope that it will be useful,
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING.  If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
 
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
 
 //
 // ISO C++ 14882: 22.8  Standard locale categories.
 
 #include <locale>
 #include <stdexcept>
+#include <limits>
 #include <langinfo.h>
-#include "c++locale_internal.h"
+#include <bits/c++locale_internal.h>
 
-namespace std 
-{
-  template<>
-    void
-    __convert_to_v(const char* __s, long& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int __base)
-    {
-      if (!(__err & ios_base::failbit))
-      {
-       char* __sanity;
-       errno = 0;
-       long __l = __strtol_l(__s, &__sanity, __base, __cloc);
-       if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-         __v = __l;
-       else
-         __err |= ios_base::failbit;
-      }
-    }
+_GLIBCXX_BEGIN_NAMESPACE(std)
 
   template<>
     void
-    __convert_to_v(const char* __s, unsigned long& __v, 
-                  ios_base::iostate& __err, const __c_locale& __cloc, 
-                  int __base)
+    __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, 
+                  const __c_locale& __cloc)
     {
-      if (!(__err & ios_base::failbit))
+      char* __sanity;
+      __v = __strtof_l(__s, &__sanity, __cloc);
+
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 23. Num_get overflow result.
+      if (__sanity == __s || *__sanity != '\0')
        {
-         char* __sanity;
-         errno = 0;
-         unsigned long __ul = __strtoul_l(__s, &__sanity, __base, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ul;
-         else
-           __err |= ios_base::failbit;
+         __v = 0.0f;
+         __err = ios_base::failbit;
        }
-    }
-
-#ifdef _GLIBCPP_USE_LONG_LONG
-  template<>
-    void
-    __convert_to_v(const char* __s, long long& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int __base)
-    {
-      if (!(__err & ios_base::failbit))
+      else if (__v == numeric_limits<float>::infinity())
        {
-         char* __sanity;
-         errno = 0;
-         long long __ll = __strtoll_l(__s, &__sanity, __base, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ll;
-         else
-           __err |= ios_base::failbit;
+         __v = numeric_limits<float>::max();
+         __err = ios_base::failbit;
        }
-    }
-
-  template<>
-    void
-    __convert_to_v(const char* __s, unsigned long long& __v, 
-                  ios_base::iostate& __err, const __c_locale& __cloc, 
-                  int __base)
-    {
-      if (!(__err & ios_base::failbit))
-       {      
-         char* __sanity;
-         errno = 0;
-         unsigned long long __ull = __strtoull_l(__s, &__sanity, __base, 
-                                                 __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ull;
-         else
-           __err |= ios_base::failbit;
-       }  
-    }
-#endif
-
-  template<>
-    void
-    __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int)
-    {
-      if (!(__err & ios_base::failbit))
+      else if (__v == -numeric_limits<float>::infinity())
        {
-         char* __sanity;
-         errno = 0;
-         float __f = __strtof_l(__s, &__sanity, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __f;
-         else
-           __err |= ios_base::failbit;
+         __v = -numeric_limits<float>::max();
+         __err = ios_base::failbit;
        }
     }
 
   template<>
     void
     __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int)
+                  const __c_locale& __cloc)
     {
-      if (!(__err & ios_base::failbit))
+      char* __sanity;
+      __v = __strtod_l(__s, &__sanity, __cloc);
+
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 23. Num_get overflow result.
+      if (__sanity == __s || *__sanity != '\0')
        {
-         char* __sanity;
-         errno = 0;
-         double __d = __strtod_l(__s, &__sanity, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __d;
-         else
-           __err |= ios_base::failbit;
+         __v = 0.0;
+         __err = ios_base::failbit;
+       }
+      else if (__v == numeric_limits<double>::infinity())
+       {
+         __v = numeric_limits<double>::max();
+         __err = ios_base::failbit;
+       }
+      else if (__v == -numeric_limits<double>::infinity())
+       {
+         __v = -numeric_limits<double>::max();
+         __err = ios_base::failbit;
        }
     }
 
   template<>
     void
     __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
-                  const __c_locale& __cloc, int)
+                  const __c_locale& __cloc)
     {
-      if (!(__err & ios_base::failbit))
+      char* __sanity;
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+      // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
+      // glibc versions.
+      __v = strtold_l(__s, &__sanity, __cloc);
+#else
+      __v = __strtold_l(__s, &__sanity, __cloc);
+#endif
+
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 23. Num_get overflow result.
+      if (__sanity == __s || *__sanity != '\0')
+       {
+         __v = 0.0l;
+         __err = ios_base::failbit;
+       }
+      else if (__v == numeric_limits<long double>::infinity())
        {
-         char* __sanity;
-         errno = 0;
-         long double __ld = __strtold_l(__s, &__sanity, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ld;
-         else
-           __err |= ios_base::failbit;
+         __v = numeric_limits<long double>::max();
+         __err = ios_base::failbit;
+       }
+      else if (__v == -numeric_limits<long double>::infinity())
+       {
+         __v = -numeric_limits<long double>::max();
+         __err = ios_base::failbit;
        }
     }
 
@@ -172,14 +132,15 @@ namespace std
     if (!__cloc)
       {
        // This named locale is not supported by the underlying OS.
-       __throw_runtime_error("attempt to create locale from unknown name");
+       __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
+                             "name not valid"));
       }
   }
   
   void
   locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
   {
-    if (_S_c_locale != __cloc)
+    if (__cloc && _S_get_c_locale() != __cloc)
       __freelocale(__cloc); 
   }
 
@@ -187,13 +148,16 @@ namespace std
   locale::facet::_S_clone_c_locale(__c_locale& __cloc)
   { return __duplocale(__cloc); }
 
-  const char* locale::_S_categories[_S_categories_size 
-                                   + _S_extra_categories_size] =
+_GLIBCXX_END_NAMESPACE
+
+_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
+
+  const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
     {
       "LC_CTYPE", 
-      "LC_NUMERIC", 
-      "LC_COLLATE", 
+      "LC_NUMERIC",
       "LC_TIME", 
+      "LC_COLLATE", 
       "LC_MONETARY",
       "LC_MESSAGES", 
       "LC_PAPER", 
@@ -203,4 +167,18 @@ namespace std
       "LC_MEASUREMENT", 
       "LC_IDENTIFICATION" 
     };
-}  // namespace std
+
+_GLIBCXX_END_NAMESPACE
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+  const char* const* const locale::_S_categories = __gnu_cxx::category_names;
+
+_GLIBCXX_END_NAMESPACE
+
+// XXX GLIBCXX_ABI Deprecated
+#ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
+#define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
+  extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
+_GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
+#endif // _GLIBCXX_LONG_DOUBLE_COMPAT