tech-userlevel archive

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

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



On Mon, Nov 10, 2008 at 07:51:06AM +0000, David Holland wrote:
> 
> (And, FWIW, I'm pretty sure the historic behavior of stdio is that "a"
> does not necessarily have this behavior; according to old security
> lore you have to open() with O_APPEND if you really want to be sure
> you're appending, e.g. in the presence of multiple writer processes.
> If you just use fopen and "a" you might get just one seek to eof at
> open time.)

There are still systems out there where fopen(..., "a") still only does
a single seek to EOF, but where fdopen(open(..., O_APPEND), ...) behaves
in the expected manner.

Except that, IIRC, that is the same system where the 'write' and 'advance'
aren't done atomically (and all the byte writes for a single write()
call aren't done together - even for shortish writes), so attempting
to share a log file between processes leaves to a corrupt mess!
(even if you open the file as a binary file not a text one).

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index