From 5a067ba02c36c5d9fadba06e34f6f9f1a1eed69c Mon Sep 17 00:00:00 2001 From: jjohnstn Date: Mon, 20 Feb 2006 23:23:59 +0000 Subject: [PATCH] 2006-02-20 Jeff Johnston * libc/stdio/fflush.c (fflush): For an fflush on a read-only stream, turn off fseek/rewind optimization as per POSIX/SUSv3. * libc/stdio/fseek.c (_fseek_r): After a successful unoptimized seek, turn off the __SNPT no-optimization flag. --- newlib/ChangeLog | 7 +++++++ newlib/libc/stdio/fflush.c | 12 +++++++++++- newlib/libc/stdio/fseek.c | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 4944b88675..940ef007c6 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2006-02-20 Jeff Johnston + + * libc/stdio/fflush.c (fflush): For an fflush on a read-only + stream, turn off fseek/rewind optimization as per POSIX/SUSv3. + * libc/stdio/fseek.c (_fseek_r): After a successful unoptimized + seek, turn off the __SNPT no-optimization flag. + 2006-02-16 Jeff Johnston * libc/sys/linux/aio.c: Define _GNU_SOURCE so struct aioinit diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c index b417e54244..05084dde08 100644 --- a/newlib/libc/stdio/fflush.c +++ b/newlib/libc/stdio/fflush.c @@ -72,8 +72,18 @@ _DEFUN(fflush, (fp), _flockfile (fp); t = fp->_flags; - if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL) + if ((t & __SWR) == 0) { + /* For a read stream, an fflush causes the next seek to be + unoptimized (i.e. forces a system-level seek). This conforms + to the POSIX and SUSv3 standards. */ + fp->_flags |= __SNPT; + _funlockfile (fp); + return 0; + } + if ((p = fp->_bf._base) == NULL) + { + /* Nothing to flush. */ _funlockfile (fp); return 0; } diff --git a/newlib/libc/stdio/fseek.c b/newlib/libc/stdio/fseek.c index 2ad98551ce..8b189ba17f 100644 --- a/newlib/libc/stdio/fseek.c +++ b/newlib/libc/stdio/fseek.c @@ -359,6 +359,13 @@ dumb: fp->_r = 0; /* fp->_w = 0; *//* unnecessary (I think...) */ fp->_flags &= ~__SEOF; + /* Reset no-optimization flag after successful seek. The + no-optimization flag may be set in the case of a read + stream that is flushed which by POSIX/SUSv3 standards, + means that a corresponding seek must not optimize. The + optimization is then allowed if no subsequent flush + is performed. */ + fp->_flags &= ~__SNPT; _funlockfile (fp); return 0; } -- 2.11.0