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

View File

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