tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: fopen(.., "a") + fseek



    Date:        Mon, 10 Nov 2008 07:51:06 +0000
    From:        David Holland <dholland-tech%netbsd.org@localhost>
    Message-ID:  <20081110075106.GB25344%netbsd.org@localhost>

  | So, a mostly aimless standards-pedantic question: does the implicit
  | seek associated with append mode actually count as a call to a file
  | positioning function,

I'll leave that to one of the people who believe that reading standards
docs is a useful thing to do ... my opinion is that you simply work out
what is right, and implement that - then if others copy, and some standards
body decides to document it, fine.   If not, ask why.  If someone else has
good reasons for acting some other way, then perhaps you (we) change.
But "the docs say" is never, of itself, a good reason for altering something
for which we have some reason for doing (on the other hand, if we were just
tossing a coin...)

In this case, you (someone, everyone voting, ...) decides whether it should
have that effect or not, and make it so (if any change is needed) and then
document it.

  | (And, FWIW, I'm pretty sure the historic behavior of stdio is that "a"
  | does not necessarily have this behavior;

Yes, O_APPEND way postdates fopen(..., "a").   One of the reasons
O_APPEND was invented was to assist with making append mode in stdio rational
(though the real reason was to defeat race conditions with wtmp).

  | If you just use fopen and "a" you might get just one seek to eof at
  | open time.)

My memory is hopeless, but I believe that original stdio (as in 7th edn)
might have been like that.   I have a recollection that a lseek() may have
been added to the output routines later, but I don't recall for sure, nor
do I have any idea when - but it wouldn't have been until the "+" modes were
added (original stdio had none of that complexity, so one seek to the end
was equivalent to what we have now unless some other process was also writing
the file.)

But for all of this you're now looking back into truly ancient history, which
may be interesting for archaeological purposes, but has essentially no
practical relevance today.

kre



Home | Main Index | Thread Index | Old Index