fopen ( ..., "a" ) --- how does the "a" work?
Richard Stevens
stevens at hsi.UUCP
Thu Dec 7 13:33:14 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"?
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 at hsi.com
... { uunet | yale } ! hsi ! stevens
More information about the Comp.unix.questions
mailing list