From 602cec7f1eb17b96525d09752fd1f0ad474e3202 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 10 Apr 2013 18:47:46 +0000 Subject: 2013-04-10 Bin Cheng * acconfig.h (_FSEEK_OPTIMIZATION): Undef * newlib.hin (_FSEEK_OPTIMIZATION): Undef * configure.in (--disable-newlib-fseek-optimization): New option. * configure: Regenerated. * libc/stdio/fflush.c (__sflush_r): Use _FSEEK_OPTIMIZATION to control fseek optimization. * libc/stdio/fseeko.c (_fseeko_r): Ditto. * libc/stdio/makebuf.c (__smakebuf_r): Ditto. * libc/stdio64/fseeko64.c (_fseeko64_r): Ditto. --- newlib/libc/stdio/fflush.c | 4 ++++ newlib/libc/stdio/fseeko.c | 3 +++ newlib/libc/stdio/makebuf.c | 4 ++++ newlib/libc/stdio64/fseeko64.c | 3 +++ 4 files changed, 14 insertions(+) (limited to 'newlib/libc') diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c index b2bde7af5..ee24cf7ca 100644 --- a/newlib/libc/stdio/fflush.c +++ b/newlib/libc/stdio/fflush.c @@ -80,10 +80,12 @@ _DEFUN(__sflush_r, (ptr, fp), t = fp->_flags; if ((t & __SWR) == 0) { +#ifdef _FSEEK_OPTIMIZATION /* 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; +#endif /* For a seekable stream with buffered read characters, we will attempt a seek to the current position now. A subsequent read will then get @@ -152,7 +154,9 @@ _DEFUN(__sflush_r, (ptr, fp), { /* Seek successful or ignorable error condition. We can clear read buffer now. */ +#ifdef _FSEEK_OPTIMIZATION fp->_flags &= ~__SNPT; +#endif fp->_r = 0; fp->_p = fp->_bf._base; if ((fp->_flags & __SOFF) && (curoff != -1 || ptr->_errno == 0)) diff --git a/newlib/libc/stdio/fseeko.c b/newlib/libc/stdio/fseeko.c index 97eafd9ca..2c9419d97 100644 --- a/newlib/libc/stdio/fseeko.c +++ b/newlib/libc/stdio/fseeko.c @@ -219,6 +219,8 @@ _DEFUN(_fseeko_r, (ptr, fp, offset, whence), if (fp->_bf._base == NULL) __smakebuf_r (ptr, fp); + +#ifdef _FSEEK_OPTIMIZATION if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) goto dumb; if ((fp->_flags & __SOPT) == 0) @@ -350,6 +352,7 @@ _DEFUN(_fseeko_r, (ptr, fp, offset, whence), * We get here if we cannot optimise the seek ... just * do it. Allow the seek function to change fp->_bf._base. */ +#endif dumb: if (_fflush_r (ptr, fp) diff --git a/newlib/libc/stdio/makebuf.c b/newlib/libc/stdio/makebuf.c index a3f47e2f7..349783ded 100644 --- a/newlib/libc/stdio/makebuf.c +++ b/newlib/libc/stdio/makebuf.c @@ -65,8 +65,10 @@ _DEFUN(__smakebuf_r, (ptr, fp), size = _DEFAULT_ASPRINTF_BUFSIZE; else size = BUFSIZ; +#ifdef _FSEEK_OPTIMIZATION /* do not try to optimise fseek() */ fp->_flags |= __SNPT; +#endif } else { @@ -76,6 +78,7 @@ _DEFUN(__smakebuf_r, (ptr, fp), #else size = BUFSIZ; #endif +#ifdef _FSEEK_OPTIMIZATION /* * Optimize fseek() only if it is a regular file. * (The test for __sseek is mainly paranoia.) @@ -91,6 +94,7 @@ _DEFUN(__smakebuf_r, (ptr, fp), } else fp->_flags |= __SNPT; +#endif } if ((p = _malloc_r (ptr, size)) == NULL) { diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c index b323f97d8..d605dd09b 100644 --- a/newlib/libc/stdio64/fseeko64.c +++ b/newlib/libc/stdio64/fseeko64.c @@ -209,6 +209,8 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence), if (fp->_bf._base == NULL) __smakebuf_r (ptr, fp); + +#if _FSEEK_OPTIMIZATION if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) goto dumb; if ((fp->_flags & __SOPT) == 0) @@ -330,6 +332,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence), * We get here if we cannot optimise the seek ... just * do it. Allow the seek function to change fp->_bf._base. */ +#endif dumb: if (_fflush_r (ptr, fp) -- cgit v1.2.3