This is the mail archive of the
mailing list for the Cygwin project.
Re: fopen with "a+" does not respect setting file read position to start of file
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
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);
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple