summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fseek.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-08-30 20:49:47 +0000
committerache <ache@FreeBSD.org>2001-08-30 20:49:47 +0000
commit831e2fb1cd4fc12dbd3e9ac761af7c87223a85b9 (patch)
treeb5233f91f9af0f77f51575cc524e26be94066702 /lib/libc/stdio/fseek.c
parent5141c6e8a2f9eeaa4aeea9db00faf05824373f78 (diff)
downloadFreeBSD-src-831e2fb1cd4fc12dbd3e9ac761af7c87223a85b9.zip
FreeBSD-src-831e2fb1cd4fc12dbd3e9ac761af7c87223a85b9.tar.gz
Try to discard some ungetc data in saved internal buffer checks too,
if offset tends to be negative.
Diffstat (limited to 'lib/libc/stdio/fseek.c')
-rw-r--r--lib/libc/stdio/fseek.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index aa886d2..8af60ba 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -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;
+ }
}
}
OpenPOWER on IntegriCloud