delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/11/14/05:17:23

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Sat, 14 Nov 2009 11:16:03 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: [BUG] fopen(..., "a") does not seek to end of file until some write operation
Message-ID: <20091114101603.GC5199@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <592384 DOT 26227 DOT qm AT web52612 DOT mail DOT re2 DOT yahoo DOT com> <4AFDC46A DOT 3070503 AT byu DOT net> <4AFE1399 DOT 9040500 AT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <4AFE1399.9040500@gmail.com>
User-Agent: Mutt/1.5.20 (2009-06-14)
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

On Nov 14 02:19, Dave Korn wrote:
> Eric Blake wrote:
> 
> > According to Salvador Fandino on 11/13/2009 1:36 PM:
> 
> >> Using ftell() after fopen(..., "a") returns 0 even when the file open for appending is not empty. AFAIK, it should return the size of the file.
> > 
> > Not a bug.  POSIX allows this behavior, and Linux does it as well.  POSIX
> > also allows BSD behavior of seeking to the end, although this is less
> > friendly to reading back a file opened with fopen(...,"a+").  So portable
> > programs can't expect either situation, and you MUST use fseek when
> > opening for append if you expect a particular position.
> 
>   I'm really confused; aren't you saying that there is exactly no difference
> between opening for append and just opening in ordinary r/w mode?  I always
> thought the positioning of the write pointer immediately after open was the
> only possible difference there could be.

Eric is just saying that you can't rely on certain values of the file
offset at any given time, except at write(2) time.  There's no good
reason to seek the file offset to the end of the file right at (f)open
time, even if "a"/O_APPEND has been specified.  See the POSIX open(2)
man page:

  O_APPEND
    If set, the file offset shall be set to the end of the file prior
    to each write.

Note "prior to each write".  See the POSIX fopen(2) man page:

  Opening a file with append mode (a as the first character in the mode
  argument) shall cause all subsequent writes to the file to be forced
  to the then current end-of-file, regardless of intervening calls to
  fseek().

Same here.  POSIX doesn't specify any other time at which the position
has to be set to EOF.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
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