a question on open() and lseek()

Chris Torek chris at umcp-cs.UUCP
Mon Apr 14 13:35:56 AEST 1986


In article <2594 at brl-smoke.ARPA> moi%brandeis.csnet at csnet-relay.arpa writes:
>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 );

There are two points to consider here.  First, the latter call does
not work in some Unix variants (notably V6, V7, and 4.1BSD).
Second, the two are not equivalent!  Indeed, this was, as far as
I can tell, the major reason for creating `append mode' in the
first place.  The open/lseek sequence suffers from the `non-atomic
system call' syndrome: multiple writers may well interfere with
each other.  When logging, for example, you are often uninterested
in sequencing, but each new message should be appended to the log
file; in append mode, the kernel guarantees that `simultaneous'
writers will not overwrite each other's messages.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix.wizards mailing list