Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucla-cs!rutgers!mephisto!ncsuvx!mcnc!rti!xyzzy!meissner From: meissner@dg-rtp.dg.com (Michael Meissner) Newsgroups: comp.unix.questions Subject: Re: fopen ( ..., "a" ) --- how does the "a" work? Message-ID: Date: 7 Dec 89 02:50:32 GMT References: <3250@hub.UUCP> Sender: usenet@xyzzy.UUCP Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 28 In-reply-to: 6600pete@hub.UUCP's message of 6 Dec 89 19:32:33 GMT In article <3250@hub.UUCP> 6600pete@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@dg-rtp.DG.COM After 12/15: meissner@osf.org