diff options
author | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2003-05-12 18:12:27 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2003-05-12 18:12:27 +0000 |
commit | 6e81c6f49c3e2ae1d91b54a53313e05ee1b4812d (patch) | |
tree | 7aec026a35820533fea51c2cf636cd67936133fb /libstdc++-v3 | |
parent | f64f0687f3ac3523b43a1eae1f70995180e4f272 (diff) | |
download | gcc-6e81c6f49c3e2ae1d91b54a53313e05ee1b4812d.zip gcc-6e81c6f49c3e2ae1d91b54a53313e05ee1b4812d.tar.gz gcc-6e81c6f49c3e2ae1d91b54a53313e05ee1b4812d.tar.bz2 |
From-SVN: r66726
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 12 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/fstream.tcc | 121 | ||||
-rw-r--r-- | libstdc++-v3/include/std/std_fstream.h | 4 |
3 files changed, 70 insertions, 67 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5089138..fd0ac14 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,17 @@ 2003-05-12 Benjamin Kosnik <bkoz@redhat.com> + * include/bits/fstream.tcc (_M_overflow): Remove unbuffered bits. + +2003-05-12 Paolo Carlini <pcarlini@unitus.it> + + * include/std/std_fstream.h (_M_convert_to_external): Change + to return bool, take two less streamsize parameters. + * include/bits/fstream.tcc (_M_convert_to_external): Tweak + consistently definition. + (_M_overflow): Adjust call points. + +2003-05-12 Benjamin Kosnik <bkoz@redhat.com> + * testsuite/27_io/basic_filebuf/underflow/10096.cc: Add weak bits. 2003-05-11 Phil Edwards <pme@gcc.gnu.org> diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index cec57ff..40d1ece 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -182,7 +182,8 @@ namespace std template<typename _CharT, typename _Traits> typename basic_filebuf<_CharT, _Traits>::int_type - basic_filebuf<_CharT, _Traits>::_M_underflow(bool __bump) + basic_filebuf<_CharT, _Traits>:: + _M_underflow(bool __bump) { int_type __ret = traits_type::eof(); const bool __testin = this->_M_mode & ios_base::in; @@ -333,6 +334,53 @@ namespace std template<typename _CharT, typename _Traits> typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>:: + _M_overflow(int_type __c) + { + int_type __ret = traits_type::eof(); + const bool __testput = this->_M_out_beg < this->_M_out_lim; + + if (__testput) + { + // Need to restore current position. The position of the external + // byte sequence (_M_file) corresponds to _M_filepos, and we need + // to move it to _M_out_beg for the write. + if (_M_filepos && _M_filepos != this->_M_out_beg) + { + off_type __off = this->_M_out_beg - _M_filepos; + _M_file.seekoff(__off, ios_base::cur); + } + + // Convert internal buffer to external representation, output. + if (_M_convert_to_external(this->_M_out_beg, + this->_M_out_lim - this->_M_out_beg)) + { + // Convert pending sequence to external representation, output. + // If eof, then just attempt sync. + if (!traits_type::eq_int_type(__c, traits_type::eof())) + { + // User code must flush when switching modes (thus + // don't sync). + char_type __pending = traits_type::to_char_type(__c); + if (_M_convert_to_external(&__pending, 1)) + { + _M_set_indeterminate(); + __ret = traits_type::not_eof(__c); + } + } + else if (!_M_file.sync()) + { + _M_set_indeterminate(); + __ret = traits_type::not_eof(__c); + } + } + } + _M_last_overflowed = true; + return __ret; + } + + template<typename _CharT, typename _Traits> + typename basic_filebuf<_CharT, _Traits>::int_type + basic_filebuf<_CharT, _Traits>:: overflow(int_type __c) { int_type __ret = traits_type::eof(); @@ -358,14 +406,16 @@ namespace std } template<typename _CharT, typename _Traits> - void + bool basic_filebuf<_CharT, _Traits>:: - _M_convert_to_external(_CharT* __ibuf, streamsize __ilen, - streamsize& __elen, streamsize& __plen) + _M_convert_to_external(_CharT* __ibuf, streamsize __ilen) { + // Sizes of external and pending output. + streamsize __elen = 0; + streamsize __plen = 0; + const locale __loc = this->getloc(); const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc); - if (__cvt.always_noconv() && __ilen) { __elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen); @@ -420,67 +470,8 @@ namespace std } } } - } - - template<typename _CharT, typename _Traits> - typename basic_filebuf<_CharT, _Traits>::int_type - basic_filebuf<_CharT, _Traits>:: - _M_overflow(int_type __c) - { - int_type __ret = traits_type::eof(); - const bool __testput = this->_M_out_beg < this->_M_out_lim; - const bool __testunbuffered = _M_file.is_open() && !this->_M_buf_size; - - if (__testput || __testunbuffered) - { - // Sizes of external and pending output. - streamsize __elen = 0; - streamsize __plen = 0; - // Need to restore current position. The position of the external - // byte sequence (_M_file) corresponds to _M_filepos, and we need - // to move it to _M_out_beg for the write. - if (_M_filepos && _M_filepos != this->_M_out_beg) - { - off_type __off = this->_M_out_beg - _M_filepos; - _M_file.seekoff(__off, ios_base::cur); - } - - // Convert internal buffer to external representation, output. - // NB: In the unbuffered case, no internal buffer exists. - if (!__testunbuffered) - _M_convert_to_external(this->_M_out_beg, - this->_M_out_lim - this->_M_out_beg, - __elen, __plen); - - // Checks for codecvt.out failures and _M_file.xsputn failures, - // respectively, inside _M_convert_to_external. - if (__testunbuffered || (__elen && __elen == __plen)) - { - // Convert pending sequence to external representation, output. - // If eof, then just attempt sync. - if (!traits_type::eq_int_type(__c, traits_type::eof())) - { - char_type __pending = traits_type::to_char_type(__c); - _M_convert_to_external(&__pending, 1, __elen, __plen); - - // User code must flush when switching modes (thus - // don't sync). - if (__elen == __plen && __elen) - { - _M_set_indeterminate(); - __ret = traits_type::not_eof(__c); - } - } - else if (!_M_file.sync()) - { - _M_set_indeterminate(); - __ret = traits_type::not_eof(__c); - } - } - } - _M_last_overflowed = true; - return __ret; + return __elen && __elen == __plen; } template<typename _CharT, typename _Traits> diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h index 0de74e6..0781f0d 100644 --- a/libstdc++-v3/include/std/std_fstream.h +++ b/libstdc++-v3/include/std/std_fstream.h @@ -353,8 +353,8 @@ namespace std * @doctodo * @endif */ - void - _M_convert_to_external(char_type*, streamsize, streamsize&, streamsize&); + bool + _M_convert_to_external(char_type*, streamsize); /** * @brief Manipulates the buffer. |