From 544f9440ab0b02d0971a148d63957f1b4232c261 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 30 Apr 2005 06:54:08 +0000 Subject: [PATCH] re PR libstdc++/21286 (filebuf::xsgetn vs pipes) 2005-04-29 Paolo Carlini Nathan Myers PR libstdc++/21286 * include/bits/fstream.tcc (basic_filebuf<>::xsgetn): Loop on short reads; remove the work-around for libstdc++/20806, not needed anymore. Co-Authored-By: Nathan Myers From-SVN: r99033 --- libstdc++-v3/ChangeLog | 8 ++++++ libstdc++-v3/include/bits/fstream.tcc | 36 ++++++++++++++++----------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 164aee42cc6..48f8a7d3f88 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2005-04-29 Paolo Carlini + Nathan Myers + + PR libstdc++/21286 + * include/bits/fstream.tcc (basic_filebuf<>::xsgetn): + Loop on short reads; remove the work-around for + libstdc++/20806, not needed anymore. + 2005-04-29 Paolo Carlini PR libstdc++/21238 diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 6915ea9b23c..40bf428e2c1 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -531,15 +531,8 @@ namespace std const bool __testin = _M_mode & ios_base::in; const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 1; -#if _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM - // About this workaround, see libstdc++/20806. - const bool __testbinary = _M_mode & ios_base::binary; - if (__n > __buflen && __check_facet(_M_codecvt).always_noconv() - && __testin && __testbinary && !_M_writing) -#else if (__n > __buflen && __check_facet(_M_codecvt).always_noconv() && __testin && !_M_writing) -#endif { // First, copy the chars already present in the buffer. const streamsize __avail = this->egptr() - this->gptr(); @@ -555,13 +548,28 @@ namespace std __n -= __avail; } - const streamsize __len = _M_file.xsgetn(reinterpret_cast(__s), - __n); - if (__len == -1) - __throw_ios_failure(__N("basic_filebuf::xsgetn " - "error reading the file")); - __ret += __len; - if (__len == __n) + // Need to loop in case of short reads (relatively common + // with pipes). + streamsize __len; + for (;;) + { + __len = _M_file.xsgetn(reinterpret_cast(__s), + __n); + if (__len == -1) + __throw_ios_failure(__N("basic_filebuf::xsgetn " + "error reading the file")); + if (__len == 0) + break; + + __n -= __len; + __ret += __len; + if (__n == 0) + break; + + __s += __len; + } + + if (__n == 0) { _M_set_buffer(0); _M_reading = true; -- 2.30.2