summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ftell.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/ftell.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/ftell.c')
-rw-r--r--lib/libc/stdio/ftell.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 38a164e..46a309c 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -118,9 +118,15 @@ ftello(fp)
if (HASUB(fp)) {
pos -= fp->_ur;
if (pos < 0) {
- errno = EBADF;
- FUNLOCKFILE(fp);
- return (-1);
+ if (-pos <= fp->_r) {
+ fp->_p -= pos;
+ fp->_r += pos;
+ pos = 0;
+ } else {
+ errno = EBADF;
+ FUNLOCKFILE(fp);
+ return (-1);
+ }
}
}
} else if ((fp->_flags & __SWR) && fp->_p != NULL) {
OpenPOWER on IntegriCloud