home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!mips!sdd.hp.com!usc!rpi!batcomputer!munnari.oz.au!bruce.cs.monash.edu.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.std.c
- Subject: Re: does "always append" apply to "a+" mode?
- Message-ID: <13851@goanna.cs.rmit.oz.au>
- Date: 30 Jul 92 04:15:44 GMT
- References: <24992@dog.ee.lbl.gov>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 48
-
- In article <24992@dog.ee.lbl.gov>, torek@horse.ee.lbl.gov (Chris Torek) writes:
- > In the section on fopen (4.9.5.3, pp. 130--131), the Standard says:
- > Opening a file with append mode (|'a'| as the first character in
- > the |mode| argument) causes all subsequent writes to the file to be
- > forced to the then current end-of-file, regardless of intervening
- > calls to the |fseek| function. ...
- >
- > To me, it seems clear that a stream opened in "a+" mode can be read at
- > any arbitrary position, but all writes to that stream are appended to
- > the underlying file.
-
- My understanding of O_APPEND in UNIX (peace; I'll get to the std.c bit soon)
- is that every write goes to the end of the file, regardless of where the
- file pointer is, and regardless of where the end of the file _was_ last time
- we looked. This means that every time I write a record to such a file, it
- is, _at the instant it goes into the file_, the last thing there.
-
- It has never been clear to me what the model is for "a" mode.
- Is it like Fortran's
- OPEN(UNIT=..., FILE='name', ACTION='WRITE', POSITION='APPEND')
- (i.e. is it just like "w" mode except for being _initially_ positioned at
- the end of the existing file), or is like like UNIX's
- open("name", O_WRONLY|O_APPEND|O_CREAT)
-
- If it is the latter, I don't quite understand how to use it. In particular,
- I don't understand what if any use I can make of ftell() or fgetpos() (there
- is where the last write finished, there is where the end of the file is right
- now, and there is where the buffered characters will actually go, and those
- three places can all be different). Indeed, it seems to me that there are
- just two ways I can use an "a" mode file:
-
- (1) Assume or ensure that no other process or FILE* refers to the file,
- and treat it as if it was "w" except for seeking to the end instead
- of truncating.
-
- (2) Assume that other processes _might_ be using the file,
- explicitly use setvbuf() to make sure the buffer is big enough to
- hold a complete formatted record, and _religiously_ use fflush()
- after writing each record (because if I don't do these things,
- the buffer might fragment my logical formatted record, and the
- fragments might be interleaved with fragments from another process).
-
- I appreciate that the ANSI standard cannot and should not make promises
- about UNIX-specific features sucha s O_APPEND; I'm not so much asking
- "can I get access to this feature" as asking "might this feature be used,
- and if so, what damage can that do to me".
- --
- You can lie with statistics ... but not to a statistician.
-