diff options
-rw-r--r-- | newlib/ChangeLog | 9 | ||||
-rw-r--r-- | newlib/libc/stdio/fflush.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdio/ftell.c | 9 | ||||
-rw-r--r-- | newlib/libc/stdio64/ftello64.c | 9 |
4 files changed, 23 insertions, 6 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 7f78ecef6b2..65c1bd79fdc 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,12 @@ +2008-03-03 Eric Blake <ebb9@byu.net> + + 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. + 2008-02-20 Eric Blake <ebb9@byu.net> Fix strtod("-0x", NULL). diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c index de32e62ea77..7a98cdf2ab0 100644 --- a/newlib/libc/stdio/fflush.c +++ b/newlib/libc/stdio/fflush.c @@ -148,6 +148,8 @@ _DEFUN(_fflush_r, (ptr, fp), fp->_p = fp->_bf._base; if (fp->_flags & __SOFF) fp->_offset = curoff; + if (HASUB (fp)) + FREEUB (ptr, fp); } else { diff --git a/newlib/libc/stdio/ftell.c b/newlib/libc/stdio/ftell.c index 21032df5804..4661dbe9383 100644 --- a/newlib/libc/stdio/ftell.c +++ b/newlib/libc/stdio/ftell.c @@ -118,9 +118,12 @@ _DEFUN(_ftell_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 diff --git a/newlib/libc/stdio64/ftello64.c b/newlib/libc/stdio64/ftello64.c index 7dc19c35106..04644ecca53 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 |