open() with O_APPEND

Robert_Toxen%anvil.UUCP at harvard.harvard.edu Robert_Toxen%anvil.UUCP at harvard.harvard.edu
Wed Apr 16 06:59:06 AEST 1986


> From: anvil!harvard!csnet-relay.arpa!moi%brandeis.csnet
> Subject: a question on open() and lseek()
> 
> The manual page for "open()" mentions that one of the flags one can specify
> with the call is O_APPEND.  It's supposed to request that all "write()"s be
> appended to the end of the file.  Is there any reason to use the sequence:
> 	f = open( file, O_WRONLY );
> 	lseek( f, 0, L_XTND );
> instead of the single call:
> 	f = open( file, O_WRONLY | O_APPEND );
> 
> I saw the sequence used in a section of code where the single call would make
> sense.
> 
> 				Moises Lejter moi%brandeis at csnet-relay.arpa

The former sequence has no advantage over the latter. The O_APPEND is fairly
new (came out in System III) and so old programs (and old programmers) use the
former.

The latter has the advantage in that it is guaranteed to work even if two or
more programs are writing to the same file. I used this to advantage to speed
up UUCP by eliminating the need to lock the LOGFILE & SYSLOG files.

Bob Toxen
Stratus Computer
{ucbvax!ihnp4,harvard}!anvil!bob
============================



More information about the Comp.unix.wizards mailing list