X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 	tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes
To: cygwin@cygwin.com
Subject: Re: fopen with "a+" does not respect setting file read position to  start of file
References: <B0E0B6C348D8AB4BAD6290DC0BDE99D47427D7442A@GVW1115EXC.americas.hpqcorp.net> <4BB482FA.3030201@ltu.se> <op.vahh3o181e62zd@balu.cs.uni-paderborn.de> <4BB4CAFE.5070605@redhat.com>
Date: Thu, 01 Apr 2010 19:13:49 +0300
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: "Matthias Andree" <matthias.andree@gmx.de>
Message-ID: <op.vaht5bol1e62zd@balu.cs.uni-paderborn.de>
In-Reply-To: <4BB4CAFE.5070605@redhat.com>
User-Agent: Opera Mail/10.51 (Win32)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Eric Blake wrote on 2010-04-01:

> On 04/01/2010 05:53 AM, Matthias Andree wrote:
>>> Well if that worked previously it was a bug.
>>
>> Not a Cygwin defect, but an application bug, and what Gavin named "work
>> around" is actually the right fix.
>>
>> POSIX explicitly states that the initial position beginning/end of file
>> in append mode is implementation-defined, and the Cygwin documentation
>> doesn't make promises either way. Linux and FreeBSD document BOF and
>> EOF, respectively.
>
> I agree that it is not a cygwin bug.  And I actually prefer Linux'
> interpretation of BOF, since it matches with the POSIX requirement that
> open(,O_APPEND|O_RDWR) be positioned at offset 0 and not at the end (it
> is only fopen that is allowed, but not required, to be at the end).  In
> fact, the release of m4 1.4.10 worked on cygwin and Linux but was broken
> on BSD because of this very portability pitfall.

Preference seconded; Solaris 10 for instance also comes up with  
ftell[o](fopen("nonemptyfile", "a+")) == 0.

The FreeBSD argument (in the libc sources) is that their approach  
applications gets use ftell[o]() right - and how this isn't reliable at  
the same time:

	/*
	 * When opening in append mode, even though we use O_APPEND,
	 * we need to seek to the end so that ftell() gets the right
	 * answer.  If the user then alters the seek pointer, or
	 * the file extends, this will fail, but there is not much
	 * we can do about this.  (We could set __SAPP and check in
	 * fseek and ftell.)
	 */
	if (oflags & O_APPEND)
		(void)_sseek(fp, (fpos_t)0, SEEK_END);

(<http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdio/fopen.c?rev=1.14>  
bottom)

-- 
Matthias Andree

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

