From: Paolo Carlini Date: Mon, 18 Jul 2005 18:31:59 +0000 (+0000) Subject: re PR libstdc++/21286 (filebuf::xsgetn vs pipes) X-Git-Tag: releases/gcc-3.4.5~322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=996cfab1427cf3b6724f36f5eeadb290f919e95e;p=thirdparty%2Fgcc.git re PR libstdc++/21286 (filebuf::xsgetn vs pipes) 2005-07-18 Paolo Carlini Nathan Myers PR libstdc++/21286 * include/bits/fstream.tcc (basic_filebuf<>::xsgetn): Loop on short reads. Co-Authored-By: Nathan Myers From-SVN: r102138 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 72851fae9444..6e645d79c149 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2005-07-18 Paolo Carlini + Nathan Myers + + PR libstdc++/21286 + * include/bits/fstream.tcc (basic_filebuf<>::xsgetn): + Loop on short reads. + 2005-05-27 Mark Mitchell * testsuite/Makefile.in: Regenerate with Automake 1.7.8. diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 25a4d48cb720..3b433ea79b05 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -535,13 +535,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;