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

Conor P. Cahill cpcahil at virtech.uucp
Fri Dec 8 00:08:13 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.

There exists an append mode for open files where the kernel automatically
places all writes at the end of file.  This is what fopen(3) will use
under unix.

Under other os's this will depend upon the capabilities of the os.

If the system has an append mode,
	 then it will probably be used.
Else If the system has a mechanism to move around a file (like unix lseek())
	it will probably be used to move to the end of the file before each
	write.
Else
	the library could just read data until it came to EOF
	and then write the data.  (Yes, this would be very inefficient)


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.questions mailing list