Try to discard some ungetc data in saved internal buffer checks too,

if offset tends to be negative.
This commit is contained in:
Andrey A. Chernov 2001-08-30 20:49:47 +00:00
parent 77f71bc5ac
commit 57935eeb3d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=82591
2 changed files with 25 additions and 7 deletions

View File

@ -151,8 +151,14 @@ _fseeko(fp, offset, whence, ltest)
if (HASUB(fp)) {
curoff -= fp->_ur;
if (curoff < 0) {
errno = EBADF;
return (-1);
if (-curoff <= fp->_r) {
fp->_p -= curoff;
fp->_r += curoff;
curoff = 0;
} else {
errno = EBADF;
return (-1);
}
}
}
} else if ((fp->_flags & __SWR) && fp->_p != NULL) {
@ -261,8 +267,14 @@ _fseeko(fp, offset, whence, ltest)
}
if (HASUB(fp)) {
curoff -= fp->_ur;
if (curoff < 0)
goto dumb;
if (curoff < 0) {
if (-curoff <= fp->_r) {
fp->_p -= curoff;
fp->_r += curoff;
curoff = 0;
} else
goto dumb;
}
}
}

View File

@ -118,9 +118,15 @@ ftello(fp)
if (HASUB(fp)) {
pos -= fp->_ur;
if (pos < 0) {
errno = EBADF;
FUNLOCKFILE(fp);
return (-1);
if (-pos <= fp->_r) {
fp->_p -= pos;
fp->_r += pos;
pos = 0;
} else {
errno = EBADF;
FUNLOCKFILE(fp);
return (-1);
}
}
}
} else if ((fp->_flags & __SWR) && fp->_p != NULL) {