summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fseek.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-08-31 14:11:14 +0000
committerache <ache@FreeBSD.org>2001-08-31 14:11:14 +0000
commitef96044374af37896b3d0581d9f4d0f245b18587 (patch)
treea2d1a1b9254a7815b37cbf9e719ce4cd5e0843f5 /lib/libc/stdio/fseek.c
parentd4e4fe55ba1f2260686035864158f84af99abac6 (diff)
downloadFreeBSD-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.
Diffstat (limited to 'lib/libc/stdio/fseek.c')
-rw-r--r--lib/libc/stdio/fseek.c30
1 files changed, 21 insertions, 9 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;
+ }
}
}
}
OpenPOWER on IntegriCloud