If file offset is smaller than internal buffer character left count, just drop

internal buffer and trust offset, not return error.
This commit is contained in:
Andrey A. Chernov 2001-08-31 14:11:14 +00:00
parent 14b62f116d
commit ee75810413
2 changed files with 30 additions and 16 deletions

View File

@ -104,7 +104,7 @@ _fseeko(fp, offset, whence, ltest)
int ltest;
{
register fpos_t (*seekfn) __P((void *, fpos_t, int));
fpos_t target, curoff;
fpos_t target, curoff, spos;
size_t n;
struct stat st;
int havepos;
@ -137,6 +137,7 @@ _fseeko(fp, offset, whence, ltest)
return (-1);
}
if (fp->_flags & __SRD) {
spos = curoff;
curoff -= fp->_r;
if (curoff < 0) {
if (HASUB(fp)) {
@ -144,8 +145,9 @@ _fseeko(fp, offset, whence, ltest)
fp->_r += curoff;
curoff = 0;
} else {
errno = EBADF;
return (-1);
fp->_p = fp->_bf._base;
fp->_r = 0;
curoff = spos;
}
}
if (HASUB(fp)) {
@ -156,8 +158,10 @@ _fseeko(fp, offset, whence, ltest)
fp->_r += curoff;
curoff = 0;
} else {
errno = EBADF;
return (-1);
fp->_p = fp->_bf._base;
fp->_r = 0;
FREEUB(fp);
curoff = spos;
}
}
}
@ -256,14 +260,18 @@ _fseeko(fp, offset, whence, ltest)
if (curoff == POS_ERR)
goto dumb;
}
spos = curoff;
curoff -= fp->_r;
if (curoff < 0) {
if (HASUB(fp)) {
fp->_p -= curoff;
fp->_r += curoff;
curoff = 0;
} else
goto dumb;
} else {
fp->_p = fp->_bf._base;
fp->_r = 0;
curoff = spos;
}
}
if (HASUB(fp)) {
curoff -= fp->_ur;
@ -272,8 +280,12 @@ _fseeko(fp, offset, whence, ltest)
fp->_p -= curoff;
fp->_r += curoff;
curoff = 0;
} else
goto dumb;
} else {
fp->_p = fp->_bf._base;
fp->_r = 0;
FREEUB(fp);
curoff = spos;
}
}
}
}

View File

@ -75,7 +75,7 @@ off_t
ftello(fp)
register FILE *fp;
{
register fpos_t pos;
register fpos_t pos, spos;
size_t n;
if (fp->_seek == NULL) {
@ -103,6 +103,7 @@ ftello(fp)
* those from ungetc) cause the position to be
* smaller than that in the underlying object.
*/
spos = pos;
pos -= fp->_r;
if (pos < 0) {
if (HASUB(fp)) {
@ -110,9 +111,9 @@ ftello(fp)
fp->_r += pos;
pos = 0;
} else {
errno = EBADF;
FUNLOCKFILE(fp);
return (-1);
fp->_p = fp->_bf._base;
fp->_r = 0;
pos = spos;
}
}
if (HASUB(fp)) {
@ -123,9 +124,10 @@ ftello(fp)
fp->_r += pos;
pos = 0;
} else {
errno = EBADF;
FUNLOCKFILE(fp);
return (-1);
fp->_p = fp->_bf._base;
fp->_r = 0;
FREEUB(fp);
pos = spos;
}
}
}