Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jul 2014 23:08:45 +0400
From:      Andrey Chernov <ache@freebsd.org>
To:        "Pedro F. Giffuni" <pfg@FreeBSD.org>, src-committers@freebsd.org,  svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r268987 - head/lib/libc/stdio
Message-ID:  <53CEB6BD.3000403@freebsd.org>
In-Reply-To: <201407221838.s6MIc0i9032540@svn.freebsd.org>
References:  <201407221838.s6MIc0i9032540@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 22.07.2014 22:38, Pedro F. Giffuni wrote:
> Author: pfg
> Date: Tue Jul 22 18:37:59 2014
> New Revision: 268987
> URL: http://svnweb.freebsd.org/changeset/base/268987
> 
> Log:
>   Revert	r268984:
>   Check for __SAPP flag before calling sflush.   This avoids
>   performance degradation compared to the previous approach.

Thanx. In this version sflush which doing physical write is never
called, only _sseek (lseek) for __SAPP. Here is the test program, run it
several times and notice ftell position increased from time to time (or
not in our old version):

#include <stdio.h>

int main(int argc, char *argv[])
{
        FILE *fp = fopen("testfile", "a");

        rewind(fp);
        fwrite("1", 1, 1, fp);
        printf("%ld\n", ftell(fp));
        fclose(fp);
}

It probably worth to be added to our test framework, but I completely
unaware how to do it.

>   
>   Submitted by:	ache
>   MFC after:	2 weeks
> 
> Modified:
>   head/lib/libc/stdio/ftell.c
> 
> Modified: head/lib/libc/stdio/ftell.c
> ==============================================================================
> --- head/lib/libc/stdio/ftell.c	Tue Jul 22 17:30:05 2014	(r268986)
> +++ head/lib/libc/stdio/ftell.c	Tue Jul 22 18:37:59 2014	(r268987)
> @@ -97,8 +97,6 @@ _ftello(FILE *fp, fpos_t *offset)
>  	 * Find offset of underlying I/O object, then
>  	 * adjust for buffered bytes.
>  	 */
> -	if (__sflush(fp))	/* may adjust seek offset on append stream */
> -		return (1);
>  	if (fp->_flags & __SOFF)
>  		pos = fp->_offset;
>  	else {
> @@ -120,6 +118,11 @@ _ftello(FILE *fp, fpos_t *offset)
>  		if (HASUB(fp))
>  			pos -= fp->_r;  /* Can be negative at this point. */
>  	} else if ((fp->_flags & __SWR) && fp->_p != NULL) {
> +		if (fp->_flags & __SAPP) {
> +			pos = _sseek(fp, (fpos_t)0, SEEK_END);
> +			if (pos == -1)
> +				return (1);
> +		}
>  		/*
>  		 * Writing.  Any buffered characters cause the
>  		 * position to be greater than that in the
> 


-- 
http://ache.vniz.net/



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