Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jul 2014 17:55:31 -0500
From:      Pedro Giffuni <pfg@freebsd.org>
To:        "Andrey A. Chernov" <ache@FreeBSD.org>, src-committers@freebsd.org,  svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r268997 - head/lib/libc/stdio
Message-ID:  <53CEEBE3.10807@freebsd.org>
In-Reply-To: <201407222249.s6MMnbNb050699@svn.freebsd.org>
References:  <201407222249.s6MMnbNb050699@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On 07/22/14 17:49, Andrey A. Chernov wrote:
> Author: ache
> Date: Tue Jul 22 22:49:37 2014
> New Revision: 268997
> URL: http://svnweb.freebsd.org/changeset/base/268997
>
> Log:
>    For "a"-mode files and rewind/fseek + fwrite combination return meaningful
>    value now, like Apple does, but avoid their __sflush physical write
>    performance degradation as much as possible.

Great ! Thank you !!

Pedro.

> Modified:
>    head/lib/libc/stdio/ftell.c
>
> Modified: head/lib/libc/stdio/ftell.c
> ==============================================================================
> --- head/lib/libc/stdio/ftell.c	Tue Jul 22 22:39:59 2014	(r268996)
> +++ head/lib/libc/stdio/ftell.c	Tue Jul 22 22:49:37 2014	(r268997)
> @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
>   #include "namespace.h"
>   #include <sys/types.h>
>   #include <errno.h>
> +#include <fcntl.h>
>   #include <limits.h>
>   #include <stdio.h>
>   #include "un-namespace.h"
> @@ -87,6 +88,7 @@ _ftello(FILE *fp, fpos_t *offset)
>   {
>   	fpos_t pos;
>   	size_t n;
> +	int dflags;
>   
>   	if (fp->_seek == NULL) {
>   		errno = ESPIPE;			/* historic practice */
> @@ -118,6 +120,22 @@ _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) {
> +		dflags = 0;
> +		if (fp->_flags & __SAPP)
> +			dflags = O_APPEND;
> +		else if (fp->_file != -1 &&
> +			 (dflags = _fcntl(fp->_file, F_GETFL)) < 0)
> +			return (1);
> +		if ((dflags & O_APPEND) &&
> +		    (pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
> +			if ((fp->_flags & __SOPT) || __sflush(fp) ||
> +			    (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
> +				return (1);
> +			else {
> +				*offset = pos;
> +				return (0);
> +			}
> +		}
>   		/*
>   		 * Writing.  Any buffered characters cause the
>   		 * position to be greater than that in the
>




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