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

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Dec 12 13:48:20 AEST 1989


In article <31276 at iuvax.cs.indiana.edu> bobmon at iuvax.cs.indiana.edu (RAMontante) writes:
>gwyn at brl.arpa (Doug Gwyn) <11775 at smoke.BRL.MIL> :
>-On a single-user non-multitasking system, a better implementation
>-[of append] would
>-be to seek to the end only on the initial open, not for each write.
>Is the process forbidden from doing an lseek, or are you allowing the
>programmer to reposition somewhere else in the file?  What is the
>semantics of the append behavior?

You must mean fseek(), as use of lseek() in conjunction with a stdio
stream can break stdio operation.

fseek() on an "a" mode stream could report failure (or, to be fancy,
it could succeed if the f.p.i. wouldn't be changed by the seek).

However, the story for an "a+" mode stream is different, because so
far as I can determine reads from the stream can be initiated anywhere
by preceding them with fseek() calls, and only writes are required to
jump to the end of the file.

Whether or not seek before write would be necessary depends on how
much state information is maintained for the stream by the stdio
implementation.



More information about the Comp.unix.questions mailing list