Help to recover from bad seek (i.e. negative or too big) happens beyond

our pre-check control. Do the same way as refill.c does when it set __SERR,
i.e. clear read and ungetc buffers. Clear EOF flag too.
This commit is contained in:
ache 2001-10-24 17:25:49 +00:00
parent d34d40c8b9
commit d21dd859f6
2 changed files with 12 additions and 5 deletions

View File

@ -297,11 +297,6 @@ _fseeko(fp, offset, whence, ltest)
dumb:
if (__sflush(fp) || _sseek(fp, (fpos_t)offset, whence) == POS_ERR)
return (-1);
if (ltest && fp->_offset > LONG_MAX) {
fp->_flags |= __SERR;
errno = EOVERFLOW;
return (-1);
}
/* success: clear EOF indicator and discard ungetc() data */
if (HASUB(fp))
FREEUB(fp);
@ -309,5 +304,10 @@ _fseeko(fp, offset, whence, ltest)
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
if (ltest && fp->_offset > LONG_MAX) {
fp->_flags |= __SERR;
errno = EOVERFLOW;
return (-1);
}
return (0);
}

View File

@ -171,6 +171,13 @@ _sseek(fp, offset, whence)
*/
if (ret < 0) {
if (errret == 0) {
if (offset != 0 || whence != SEEK_CUR) {
if (HASUB(fp))
FREEUB(fp);
fp->_p = fp->_bf._base;
fp->_r = 0;
fp->_flags &= ~__SEOF;
}
fp->_flags |= __SERR;
errno = EINVAL;
} else if (errret == ESPIPE)