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 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: cygwin AT cygwin DOT com Subject: Re: fopen with "a+" does not respect setting file read position to start of file References: <4BB482FA DOT 3030201 AT ltu DOT se> <4BB4CAFE DOT 5070605 AT redhat DOT com> Date: Thu, 01 Apr 2010 19:13:49 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Matthias Andree" Message-ID: 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 Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , 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); ( 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