]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/config/locale/gnu/codecvt_members.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / gnu / codecvt_members.cc
index bc454228d672cff2942590e155a21758b1d8d2a2..f67a17afd1801b3c5ebc541270eec2ead40ba342 100644 (file)
@@ -1,11 +1,11 @@
 // std::codecvt implementation details, GNU version -*- C++ -*-
 
-// Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2002-2020 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// 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.2.1.5 - Template class codecvt
 // Written by Benjamin Kosnik <bkoz@redhat.com>
 
 #include <locale>
+#include <cstdlib>  // For MB_CUR_MAX
+#include <climits>  // For MB_LEN_MAX
 #include <bits/c++locale_internal.h>
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Specializations.
 #ifdef _GLIBCXX_USE_WCHAR_T
   codecvt_base::result
   codecvt<wchar_t, char, mbstate_t>::
-  do_out(state_type& __state, const intern_type* __from, 
+  do_out(state_type& __state, const intern_type* __from,
         const intern_type* __from_end, const intern_type*& __from_next,
         extern_type* __to, extern_type* __to_end,
         extern_type*& __to_next) const
@@ -95,14 +94,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
          {
            extern_type __buf[MB_LEN_MAX];
            __tmp_state = __state;
-           const size_t __conv = wcrtomb(__buf, *__from_next, &__tmp_state);
-           if (__conv > static_cast<size_t>(__to_end - __to_next))
+           const size_t __conv2 = wcrtomb(__buf, *__from_next, &__tmp_state);
+           if (__conv2 > static_cast<size_t>(__to_end - __to_next))
              __ret = partial;
            else
              {
-               memcpy(__to_next, __buf, __conv);
+               memcpy(__to_next, __buf, __conv2);
                __state = __tmp_state;
-               __to_next += __conv;
+               __to_next += __conv2;
                ++__from_next;
              }
          }
@@ -112,12 +111,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     __uselocale(__old);
 #endif
 
-    return __ret; 
+    return __ret;
   }
-  
+
   codecvt_base::result
   codecvt<wchar_t, char, mbstate_t>::
-  do_in(state_type& __state, const extern_type* __from, 
+  do_in(state_type& __state, const extern_type* __from,
        const extern_type* __from_end, const extern_type*& __from_next,
        intern_type* __to, intern_type* __to_end,
        intern_type*& __to_next) const
@@ -161,12 +160,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                  break;
              }
            __from_next = __from;
-           __state = __tmp_state;          
+           __state = __tmp_state;
            __ret = error;
          }
        else if (__from_next && __from_next < __from_chunk_end)
          {
-           // It is unclear what to return in this case (see DR 382). 
+           // It is unclear what to return in this case (see DR 382).
            __to_next += __conv;
            __ret = partial;
          }
@@ -181,7 +180,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
            if (__to_next < __to_end)
              {
                // XXX Probably wrong for stateful encodings
-               __tmp_state = __state;          
+               __tmp_state = __state;
                ++__from_next;
                *__to_next++ = L'\0';
              }
@@ -194,10 +193,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     __uselocale(__old);
 #endif
 
-    return __ret; 
+    return __ret;
   }
 
-  int 
+  int
   codecvt<wchar_t, char, mbstate_t>::
   do_encoding() const throw()
   {
@@ -213,9 +212,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     __uselocale(__old);
 #endif
     return __ret;
-  }  
+  }
 
-  int 
+  int
   codecvt<wchar_t, char, mbstate_t>::
   do_max_length() const throw()
   {
@@ -229,8 +228,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 #endif
     return __ret;
   }
-  
-  int 
+
+  int
   codecvt<wchar_t, char, mbstate_t>::
   do_length(state_type& __state, const extern_type* __from,
            const extern_type* __end, size_t __max) const
@@ -245,10 +244,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     // mbsnrtowcs is *very* fast but stops if encounters NUL characters:
     // in case we advance past it and then continue, in a loop.
     // NB: mbsnrtowcs is a GNU extension
-  
+
     // A dummy internal buffer is needed in order for mbsnrtocws to consider
     // its fourth parameter (it wouldn't with NULL as first parameter).
-    wchar_t* __to = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t) 
+    wchar_t* __to = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t)
                                                           * __max));
     while (__from < __end && __max)
       {
@@ -270,7 +269,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
            // mbrtowc.
            for (__from = __tmp_from;; __from += __conv)
              {
-               __conv = mbrtowc(NULL, __from, __end - __from,
+               __conv = mbrtowc(0, __from, __end - __from,
                                 &__tmp_state);
                if (__conv == static_cast<size_t>(-1)
                    || __conv == static_cast<size_t>(-2))
@@ -282,7 +281,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
          }
        if (!__from)
          __from = __from_chunk_end;
-       
+
        __ret += __from - __tmp_from;
        __max -= __conv;
 
@@ -300,8 +299,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     __uselocale(__old);
 #endif
 
-    return __ret; 
+    return __ret;
   }
 #endif
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace