]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/21286 (filebuf::xsgetn vs pipes)
authorPaolo Carlini <pcarlini@suse.de>
Mon, 18 Jul 2005 18:31:59 +0000 (18:31 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 18 Jul 2005 18:31:59 +0000 (18:31 +0000)
2005-07-18  Paolo Carlini  <pcarlini@suse.de>
    Nathan Myers  <ncm@cantrip.org>

PR libstdc++/21286
* include/bits/fstream.tcc (basic_filebuf<>::xsgetn):
Loop on short reads.

Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r102138

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fstream.tcc

index 72851fae9444f44dea8d569f32de1c875512218d..6e645d79c149ac24717872034354717703ab5da2 100644 (file)
@@ -1,3 +1,10 @@
+2005-07-18  Paolo Carlini  <pcarlini@suse.de>
+           Nathan Myers  <ncm@cantrip.org>
+
+       PR libstdc++/21286
+       * include/bits/fstream.tcc (basic_filebuf<>::xsgetn):
+       Loop on short reads.
+
 2005-05-27  Mark Mitchell  <mark@codesourcery.com>
 
        * testsuite/Makefile.in: Regenerate with Automake 1.7.8.
index 25a4d48cb7207c6093b64a16c29e1329c340b4b3..3b433ea79b056abafb5a105c90c715ba4b7ad6fb 100644 (file)
@@ -535,13 +535,28 @@ namespace std
               __n -= __avail;
             }
 
-          const streamsize __len = _M_file.xsgetn(reinterpret_cast<char*>(__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<char*>(__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;