Revert "newlib: fix fseek optimization with SEEK_CUR"

This reverts commit 59362c80e3.

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>
This commit is contained in:
Corinna Vinschen 2020-01-29 18:47:33 +01:00
parent f36262d56a
commit 2607f00423
2 changed files with 50 additions and 12 deletions

View File

@ -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;

View File

@ -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;