Bob Friesenhahn <bfriesen <at> simple.dallas.tx.us> writes:
> > There is a known bug in m4 1.4.10 on platforms where fopen(..., "a+")
> > opens at the tail of a file, rather than the head. It looks like this is
> > what is biting you.
The bug is already fixed in M4 CVS; using the patch from the referenced mail.
>
> Facinating. I would expect opening for append to open at the tail
> (end) of the file although I find your use of 'head' and 'tail' to be
> confusing since a file is not a queue.
POSIX says the state of the first ftell() on a file after fopen("a+") is
implementation-defined - it can be either offset 0 (as glibc) or the end of the
file (as on BSD). It isn't until you do either an explicit seek (which is what
my m4 patch adds) or a write that the position is then well-defined.
> It sounds like your code is fighting against the intentions of "a+"
> and that the seek in your referenced patch will be ignored by FreeBSD
> and OS X and should probably be ignored by Solaris as well.
No, no problem with my code, once I added the requisite seek.
>
> Maybe freopen() can help?
Not necessary here. If fopen()/fseek() can't solve the problem, freopen() won't
help either.
--
Eric Blake