diff options
author | Eric Blake <eblake@redhat.com> | 2008-03-04 02:22:36 +0000 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2008-03-04 02:22:36 +0000 |
commit | 9ae00e9e07beb3bca4d81e18dd5209e0d9234644 (patch) | |
tree | b052594d6f8fa7653ab3cccb9497bb8af6646397 /newlib/libc/stdio64/ftello64.c | |
parent | be62101c605591b8cd8764d283d274d0defe749b (diff) | |
download | cygnal-9ae00e9e07beb3bca4d81e18dd5209e0d9234644.tar.gz cygnal-9ae00e9e07beb3bca4d81e18dd5209e0d9234644.tar.bz2 cygnal-9ae00e9e07beb3bca4d81e18dd5209e0d9234644.zip |
Fix ftell bug after ungetc.
* libc/stdio/ftell.c (_ftell_r): Don't flush ungetc buffer on
ftell.
* libc/stdio64/ftello64.c (_ftello64_r): Likewise.
* libc/stdio/fflush.c (_fflush_r): Clear unget buffer when
repositioning underlying fd offset.
-------------------------------------------------------------------
Diffstat (limited to 'newlib/libc/stdio64/ftello64.c')
-rw-r--r-- | newlib/libc/stdio64/ftello64.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/newlib/libc/stdio64/ftello64.c b/newlib/libc/stdio64/ftello64.c index 2fdfb784e..51dcd2796 100644 --- a/newlib/libc/stdio64/ftello64.c +++ b/newlib/libc/stdio64/ftello64.c @@ -108,9 +108,12 @@ _DEFUN (_ftello64_r, (ptr, fp), return -1L; } - /* Find offset of underlying I/O object, then - adjust for buffered bytes. */ - _fflush_r (ptr, fp); /* may adjust seek offset on append stream */ + /* Find offset of underlying I/O object, then adjust for buffered + bytes. Flush a write stream, since the offset may be altered if + the stream is appending. Do not flush a read stream, since we + must not lose the ungetc buffer. */ + if (fp->_flags & __SWR) + _fflush_r (ptr, fp); if (fp->_flags & __SOFF) pos = fp->_offset; else |