diff options
author | ache <ache@FreeBSD.org> | 2001-08-31 14:11:14 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-08-31 14:11:14 +0000 |
commit | ef96044374af37896b3d0581d9f4d0f245b18587 (patch) | |
tree | a2d1a1b9254a7815b37cbf9e719ce4cd5e0843f5 | |
parent | d4e4fe55ba1f2260686035864158f84af99abac6 (diff) | |
download | FreeBSD-src-ef96044374af37896b3d0581d9f4d0f245b18587.zip FreeBSD-src-ef96044374af37896b3d0581d9f4d0f245b18587.tar.gz |
If file offset is smaller than internal buffer character left count, just drop
internal buffer and trust offset, not return error.
-rw-r--r-- | lib/libc/stdio/fseek.c | 30 | ||||
-rw-r--r-- | lib/libc/stdio/ftell.c | 16 |
2 files changed, 30 insertions, 16 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 8af60ba..4e3d5cc 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -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; + } } } } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 46a309c..33184c5 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -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; } } } |