Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2020-01-29 20:47:33 +0300
committerCorinna Vinschen <corinna@vinschen.de>2020-01-29 20:53:44 +0300
commit2607f00423ead393f24b81b9fe5a39a37e036af8 (patch)
tree73f63d13d44b15f2cd0cfa10d25a4a86ab5c553a
parentf36262d56ac78f04de147746ce4a85c6155e4a23 (diff)
Revert "newlib: fix fseek optimization with SEEK_CUR"
This reverts commit 59362c80e3a02c011fd0ef3d7f07a20098d2a9d5. This breaks gnulib's autoconf test for POSIX compatibility of fflush/fseek. After fflush/fseek, ftello and lseek are out of sync, with lseek having the wrong offset. This breaks backward compatibility with Cygwin applications. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--newlib/libc/stdio/fseeko.c31
-rw-r--r--newlib/libc/stdio64/fseeko64.c31
2 files changed, 50 insertions, 12 deletions
diff --git a/newlib/libc/stdio/fseeko.c b/newlib/libc/stdio/fseeko.c
index bbf1af43e..3e0f9e90b 100644
--- a/newlib/libc/stdio/fseeko.c
+++ b/newlib/libc/stdio/fseeko.c
@@ -141,12 +141,31 @@ _fseeko_r (struct _reent *ptr,
switch (whence)
{
case SEEK_CUR:
- curoff = _ftello_r(ptr, fp);
- if (curoff == -1L)
- {
- _newlib_flockfile_exit (fp);
- return EOF;
- }
+ /*
+ * In order to seek relative to the current stream offset,
+ * we have to first find the current stream offset a la
+ * ftell (see ftell for details).
+ */
+ _fflush_r (ptr, fp); /* may adjust seek offset on append stream */
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else
+ {
+ curoff = seekfn (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR);
+ if (curoff == -1L)
+ {
+ _newlib_flockfile_exit (fp);
+ return EOF;
+ }
+ }
+ if (fp->_flags & __SRD)
+ {
+ curoff -= fp->_r;
+ if (HASUB (fp))
+ curoff -= fp->_ur;
+ }
+ else if (fp->_flags & __SWR && fp->_p != NULL)
+ curoff += fp->_p - fp->_bf._base;
offset += curoff;
whence = SEEK_SET;
diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c
index f38005570..0672086a3 100644
--- a/newlib/libc/stdio64/fseeko64.c
+++ b/newlib/libc/stdio64/fseeko64.c
@@ -142,12 +142,31 @@ _fseeko64_r (struct _reent *ptr,
switch (whence)
{
case SEEK_CUR:
- curoff = _ftello64_r(ptr, fp);
- if (curoff == -1L)
- {
- _newlib_flockfile_exit (fp);
- return EOF;
- }
+ /*
+ * In order to seek relative to the current stream offset,
+ * we have to first find the current stream offset a la
+ * ftell (see ftell for details).
+ */
+ _fflush_r (ptr, fp); /* may adjust seek offset on append stream */
+ if (fp->_flags & __SOFF)
+ curoff = fp->_offset;
+ else
+ {
+ curoff = seekfn (ptr, fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
+ if (curoff == -1L)
+ {
+ _newlib_flockfile_exit(fp);
+ return EOF;
+ }
+ }
+ if (fp->_flags & __SRD)
+ {
+ curoff -= fp->_r;
+ if (HASUB (fp))
+ curoff -= fp->_ur;
+ }
+ else if (fp->_flags & __SWR && fp->_p != NULL)
+ curoff += fp->_p - fp->_bf._base;
offset += curoff;
whence = SEEK_SET;