delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/04/01/12:14:10

X-Recipient: archive-cygwin AT delorie DOT 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
To: cygwin AT cygwin DOT com
Subject: Re: fopen with "a+" does not respect setting file read position to start of file
References: <B0E0B6C348D8AB4BAD6290DC0BDE99D47427D7442A AT GVW1115EXC DOT americas DOT hpqcorp DOT net> <4BB482FA DOT 3030201 AT ltu DOT se> <op DOT vahh3o181e62zd AT balu DOT cs DOT uni-paderborn DOT de> <4BB4CAFE DOT 5070605 AT redhat DOT com>
Date: Thu, 01 Apr 2010 19:13:49 +0300
MIME-Version: 1.0
From: "Matthias Andree" <matthias DOT andree AT gmx DOT 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 AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019