Mail Archives: djgpp-workers/2001/04/01/04:46:34
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 -