fopen ( ..., "a" ) --- how does the "a" work?

Michael Meissner meissner at dg-rtp.dg.com
Thu Dec 7 13:50:32 AEST 1989


In article <3250 at hub.UUCP> 6600pete at hub.UUCP writes:

|  When one opens a file under *most* flavors of UN*X (I realize this is
|  the kind of thing that will be system-dependent, though it oughtn't)
|  with fopen ( ..., "a" ), the file mark is supposed to be moved to EOF
|  before every write. Now, how is this done? Are there two system calls,
|  one to move the file mark and one to do the write, or is there one
|  system call, "append"? If the latter, then this is an easier solution
|  for a problem I have than figuring out how to do record locking.

In "modern" Unixes (ie, System V.[01234], Berkeley BSD 4.[23],
possibly eariler in System III, and Berkeley 4.1, but I don't have
manuals for them), the open system call takes a flag (O_APPEND) that
says to reset the file position to the end of the file whenever a
write system call occurs.  On a filesystem local to the machine, this
is done atomically with the write call.  I'm not sure whether this is
guaranteed to be atomic under NFS, but I suspect not, particularly if
the NFS server is not a UNIX system (such as a VAX running VMS or IBM
mainframe).

My version 7 manual does not list any flags for open, and the fopen
man page does not make any promises about ruber-banding the file
position to the end of the file.

--
--
Michael Meissner, Data General.
Until 12/15:	meissner at dg-rtp.DG.COM
After 12/15:	meissner at osf.org



More information about the Comp.unix.questions mailing list