1169691Skan// Stream buffer classes -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. 4169691Skan// 5169691Skan// This file is part of the GNU ISO C++ Library. This library is free 6169691Skan// software; you can redistribute it and/or modify it under the 7169691Skan// terms of the GNU General Public License as published by the 8169691Skan// Free Software Foundation; either version 2, or (at your option) 9169691Skan// any later version. 10169691Skan 11169691Skan// This library is distributed in the hope that it will be useful, 12169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14169691Skan// GNU General Public License for more details. 15169691Skan 16169691Skan// You should have received a copy of the GNU General Public License along 17169691Skan// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19169691Skan// USA. 20169691Skan 21169691Skan// As a special exception, you may use this file as part of a free software 22169691Skan// library without restriction. Specifically, if other files instantiate 23169691Skan// templates or use macros or inline functions from this file, or you compile 24169691Skan// this file and link it with other files to produce an executable, this 25169691Skan// file does not by itself cause the resulting executable to be covered by 26169691Skan// the GNU General Public License. This exception does not however 27169691Skan// invalidate any other reasons why the executable file might be covered by 28169691Skan// the GNU General Public License. 29169691Skan 30169691Skan// 31169691Skan// ISO C++ 14882: 27.5 Stream buffers 32169691Skan// 33169691Skan 34169691Skan#include <streambuf> 35169691Skan 36169691Skan_GLIBCXX_BEGIN_NAMESPACE(std) 37169691Skan 38169691Skan template<> 39169691Skan streamsize 40169691Skan __copy_streambufs_eof(basic_streambuf<char>* __sbin, 41169691Skan basic_streambuf<char>* __sbout, bool& __ineof) 42169691Skan { 43169691Skan typedef basic_streambuf<char>::traits_type traits_type; 44169691Skan streamsize __ret = 0; 45169691Skan __ineof = true; 46169691Skan traits_type::int_type __c = __sbin->sgetc(); 47169691Skan while (!traits_type::eq_int_type(__c, traits_type::eof())) 48169691Skan { 49169691Skan const streamsize __n = __sbin->egptr() - __sbin->gptr(); 50169691Skan if (__n > 1) 51169691Skan { 52169691Skan const streamsize __wrote = __sbout->sputn(__sbin->gptr(), __n); 53169691Skan __sbin->gbump(__wrote); 54169691Skan __ret += __wrote; 55169691Skan if (__wrote < __n) 56169691Skan { 57169691Skan __ineof = false; 58169691Skan break; 59169691Skan } 60169691Skan __c = __sbin->underflow(); 61169691Skan } 62169691Skan else 63169691Skan { 64169691Skan __c = __sbout->sputc(traits_type::to_char_type(__c)); 65169691Skan if (traits_type::eq_int_type(__c, traits_type::eof())) 66169691Skan { 67169691Skan __ineof = false; 68169691Skan break; 69169691Skan } 70169691Skan ++__ret; 71169691Skan __c = __sbin->snextc(); 72169691Skan } 73169691Skan } 74169691Skan return __ret; 75169691Skan } 76169691Skan 77169691Skan#ifdef _GLIBCXX_USE_WCHAR_T 78169691Skan template<> 79169691Skan streamsize 80169691Skan __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin, 81169691Skan basic_streambuf<wchar_t>* __sbout, bool& __ineof) 82169691Skan { 83169691Skan typedef basic_streambuf<wchar_t>::traits_type traits_type; 84169691Skan streamsize __ret = 0; 85169691Skan __ineof = true; 86169691Skan traits_type::int_type __c = __sbin->sgetc(); 87169691Skan while (!traits_type::eq_int_type(__c, traits_type::eof())) 88169691Skan { 89169691Skan const streamsize __n = __sbin->egptr() - __sbin->gptr(); 90169691Skan if (__n > 1) 91169691Skan { 92169691Skan const streamsize __wrote = __sbout->sputn(__sbin->gptr(), __n); 93169691Skan __sbin->gbump(__wrote); 94169691Skan __ret += __wrote; 95169691Skan if (__wrote < __n) 96169691Skan { 97169691Skan __ineof = false; 98169691Skan break; 99169691Skan } 100169691Skan __c = __sbin->underflow(); 101169691Skan } 102169691Skan else 103169691Skan { 104169691Skan __c = __sbout->sputc(traits_type::to_char_type(__c)); 105169691Skan if (traits_type::eq_int_type(__c, traits_type::eof())) 106169691Skan { 107169691Skan __ineof = false; 108169691Skan break; 109169691Skan } 110169691Skan ++__ret; 111169691Skan __c = __sbin->snextc(); 112169691Skan } 113169691Skan } 114169691Skan return __ret; 115169691Skan } 116169691Skan#endif 117169691Skan 118169691Skan_GLIBCXX_END_NAMESPACE 119