summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-09-01 11:18:53 +0000
committerache <ache@FreeBSD.org>2001-09-01 11:18:53 +0000
commit116ee96d9df70379bb81e6984c869556395bd5fd (patch)
tree4a6993e19631d294b1a6238482dc8b51a8b586ce /lib
parenta34f6bb0fc489e5b698fc31c3e334b17a8e28cfd (diff)
downloadFreeBSD-src-116ee96d9df70379bb81e6984c869556395bd5fd.zip
FreeBSD-src-116ee96d9df70379bb81e6984c869556395bd5fd.tar.gz
If position is underflowed, don't try to hide that fact by recovery, just
return EIO and set __SERR to mark stream as inconsistent.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/ftell.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index a0fd175..7784c67 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -97,7 +97,7 @@ _ftello(fp, offset)
register FILE *fp;
fpos_t *offset;
{
- register fpos_t pos, spos;
+ register fpos_t pos;
size_t n;
if (fp->_seek == NULL) {
@@ -109,12 +109,10 @@ _ftello(fp, offset)
* Find offset of underlying I/O object, then
* adjust for buffered bytes.
*/
- if (fp->_flags & __SOFF) {
+ if (fp->_flags & __SOFF)
pos = fp->_offset;
- spos = -1;
- } else {
-get_real_pos:
- spos = pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+ else {
+ pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
if (pos == -1)
return (1);
}
@@ -125,17 +123,9 @@ get_real_pos:
* smaller than that in the underlying object.
*/
if ((pos -= (HASUB(fp) ? fp->_ur : fp->_r)) < 0) {
- /* Lost position, resync. */
- if (HASUB(fp)) {
- fp->_extra->_up = fp->_bf._base;
- fp->_ur = 0;
- } else {
- fp->_p = fp->_bf._base;
- fp->_r = 0;
- }
- if (spos == -1)
- goto get_real_pos;
- pos = spos;
+ fp->_flags |= __SERR;
+ errno = EIO;
+ return (1);
}
if (HASUB(fp))
pos -= fp->_r; /* Can be negative at this point. */
OpenPOWER on IntegriCloud