format clean up
[official-gcc.git] / libstdc++-v3 / src / streambuf.cc
blob5bcd0ea8d58516807ecf9e5ccfbe70e925eb4ec6
1 // Stream buffer classes -*- C++ -*-
3 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 // Free Software Foundation, Inc.
5 //
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 3, or (at your option)
10 // any later version.
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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
27 // ISO C++ 14882: 27.5 Stream buffers
30 #include <streambuf>
32 namespace std _GLIBCXX_VISIBILITY(default)
34 _GLIBCXX_BEGIN_NAMESPACE_VERSION
36 template<>
37 streamsize
38 __copy_streambufs_eof(basic_streambuf<char>* __sbin,
39 basic_streambuf<char>* __sbout, bool& __ineof)
41 typedef basic_streambuf<char>::traits_type traits_type;
42 streamsize __ret = 0;
43 __ineof = true;
44 traits_type::int_type __c = __sbin->sgetc();
45 while (!traits_type::eq_int_type(__c, traits_type::eof()))
47 const streamsize __n = __sbin->egptr() - __sbin->gptr();
48 if (__n > 1)
50 const streamsize __wrote = __sbout->sputn(__sbin->gptr(), __n);
51 __sbin->__safe_gbump(__wrote);
52 __ret += __wrote;
53 if (__wrote < __n)
55 __ineof = false;
56 break;
58 __c = __sbin->underflow();
60 else
62 __c = __sbout->sputc(traits_type::to_char_type(__c));
63 if (traits_type::eq_int_type(__c, traits_type::eof()))
65 __ineof = false;
66 break;
68 ++__ret;
69 __c = __sbin->snextc();
72 return __ret;
75 #ifdef _GLIBCXX_USE_WCHAR_T
76 template<>
77 streamsize
78 __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin,
79 basic_streambuf<wchar_t>* __sbout, bool& __ineof)
81 typedef basic_streambuf<wchar_t>::traits_type traits_type;
82 streamsize __ret = 0;
83 __ineof = true;
84 traits_type::int_type __c = __sbin->sgetc();
85 while (!traits_type::eq_int_type(__c, traits_type::eof()))
87 const streamsize __n = __sbin->egptr() - __sbin->gptr();
88 if (__n > 1)
90 const streamsize __wrote = __sbout->sputn(__sbin->gptr(), __n);
91 __sbin->__safe_gbump(__wrote);
92 __ret += __wrote;
93 if (__wrote < __n)
95 __ineof = false;
96 break;
98 __c = __sbin->underflow();
100 else
102 __c = __sbout->sputc(traits_type::to_char_type(__c));
103 if (traits_type::eq_int_type(__c, traits_type::eof()))
105 __ineof = false;
106 break;
108 ++__ret;
109 __c = __sbin->snextc();
112 return __ret;
114 #endif
116 _GLIBCXX_END_NAMESPACE_VERSION
117 } // namespace