about summary refs log tree commit diff
path: root/libio/fileops.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2014-12-04 08:13:28 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2014-12-04 08:13:28 +0530
commitfe8b4d98e9ac371238388469cb74011cb2120343 (patch)
treebd78796417f00a31e2112af9fa724b0b732731b0 /libio/fileops.c
parent61b4f792e03facb456036b3f631d58d4f53b8075 (diff)
downloadglibc-fe8b4d98e9ac371238388469cb74011cb2120343.tar.gz
glibc-fe8b4d98e9ac371238388469cb74011cb2120343.tar.xz
glibc-fe8b4d98e9ac371238388469cb74011cb2120343.zip
Reset cached offset when reading to end of stream (BZ #17653)
POSIX allows applications to switch file handles when a read results
in an end of file.  Unset the cached offset at this point so that it
is queried again.
Diffstat (limited to 'libio/fileops.c')
-rw-r--r--libio/fileops.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libio/fileops.c b/libio/fileops.c
index dca359179f..ee50b72aec 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -615,7 +615,13 @@ _IO_new_file_underflow (fp)
   }
   fp->_IO_read_end += count;
   if (count == 0)
-    return EOF;
+    {
+      /* If a stream is read to EOF, the calling application may switch active
+	 handles.  As a result, our offset cache would no longer be valid, so
+	 unset it.  */
+      fp->_offset = _IO_pos_BAD;
+      return EOF;
+    }
   if (fp->_offset != _IO_pos_BAD)
     _IO_pos_adjust (fp->_offset, count);
   return *(unsigned char *) fp->_IO_read_ptr;