delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/04/01/04:46:34

Date: Sun, 1 Apr 2001 10:42:50 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Martin Str|mberg <ams AT ludd DOT luth DOT se>, djgpp-workers AT delorie DOT com
Subject: Re: Bug00323, final? (LONG)
In-Reply-To: <3791-Sat31Mar2001222212+0200-eliz@is.elta.co.il>
Message-ID: <Pine.SUN.3.91.1010401104226.15706P-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sat, 31 Mar 2001, Eli Zaretskii wrote:

> > -  if (*mode == 'a')
> > -    lseek(fd, 0, SEEK_END);
> > -
> 
> What does ANSI C say about the file stream position right after it is
> open with "a" mode?  If it says it should be at the file's end, you
> cannot remove the above lseek.

This is from the draft:

       7.19.3  Files

       [#1] A stream is associated with an external file (which may
       be a physical device) by opening a file, which  may  involve
       creating  a  new file.  Creating an existing file causes its
       former contents to be discarded, if necessary.   If  a  file
       can  support  positioning  requests (such as a disk file, as
       opposed to a  terminal),  then  a  file  position  indicator
       associated  with  the  stream  is  positioned  at  the start
       (character number zero) of the  file,  unless  the  file  is
       opened  with append mode in which case it is implementation-
       defined whether the file  position  indicator  is  initially
       positioned  at  the  beginning  or the end of the file.

Note the last sentence: the file position is implementation defined.
This probably means that different library implementations do it
differently.  Can someone please check what happens on Unix and
GNU/Linux systems?  A simple test program which opens an existing file
with "a" and then calls ftell and prints the result is all you need.

The Posix draft seem to say the same.  It would be interesting to know
what happens with open and fdopen on Unix systems, btw.

- Raw text -


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