Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!hsi!stevens From: stevens@hsi.UUCP (Richard Stevens) Newsgroups: comp.unix.questions Subject: Re: fopen ( ..., "a" ) --- how does the "a" work? Summary: O_APPEND flag to open Message-ID: <895@hsi86.hsi.UUCP> Date: 7 Dec 89 02:33:14 GMT References: <3250@hub.UUCP> Organization: Health Systems Intl., New Haven, CT Lines: 25 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"? With System V Release 2, fopen specifies the O_APPEND flag to the open system call if you specify the "a" mode. This has the kernel move the inode's read/write offset to the end of the file every time you write to the file. Hence only one system call is required. I suspect the later release of System V also do this. Interesting, however, is that the 4.3BSD source differs. It does an lseek to the EOF when fopen is called, and that's it. 4.3 does have an O_APPEND option to open, but it doesn't appear to be used. The 4.3 man page for fopen also doesn't go to the lengths that the system V man page does specifying that "a" really means that every write gets appended, regardless of the file's current position. Richard Stevens Health Systems International, New Haven, CT stevens@hsi.com ... { uunet | yale } ! hsi ! stevens