Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Sep 2001 07:48:36 +0400
From:      "Andrey A. Chernov" <ache@nagual.pp.ru>
To:        Alfred Perlstein <bright@mu.org>
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/lib/libc/stdio setvbuf.c
Message-ID:  <20010903074836.A98027@nagual.pp.ru>
In-Reply-To: <20010903070334.A97368@nagual.pp.ru>
References:  <200109030235.f832ZAg46853@freefall.freebsd.org> <20010902214528.J81307@elvis.mu.org> <20010903070334.A97368@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 03, 2001 at 07:03:37 +0400, Andrey A. Chernov wrote:
> Stdio try to optimize seeks internally to keep file offset in memory
> without additional fp->_seek, commonly lseek call (and use __SOFF for it).
> It can be done correctly only for regular files and when fp->_seek not
> changed to non-standard function. Character devices (f.e. normal stdio)
> often move pointer by themselfs, so keeping offset in memory for them
> leads to incorrect offset. Stdio try to detect regular files with fp->seek
> set to standard __seek and set __SOPT flag for them. It means that file
> can be optimized. __SOFF is one sort of optimizations, it means we have
> valid file offset in memory. When setvbuf.c clears __SOPT, no
> optimizations allowed including __SOFF, so __SOFF must be removed too.

Try this test program on some old system stdio and with my changes, and
see the differences:

-----------------------------------------
#include <stdio.h>

main()
{
	long i1, i2;

	i1 = ftell(stdout);

	system("/bin/echo 123");

	i2 = ftell(stdout);

	printf("%ld %ld\n", i1, i2);
}
-----------------------------------------

Of course, you (or somebody else) can say that stdio needs to keep/tell
its internal position only, but as you notice first ftell() with old and
new stdio both tells absolute stdout position, i.e. some big number (if it
suppose to tell stdio internal position instead, there must be 0).

-- 
Andrey A. Chernov
http://ache.pp.ru/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010903074836.A98027>