home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2373 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  2.3 KB

  1. Path: sparky!uunet!usc!sdd.hp.com!hplabs!ucbvax!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
  2. From: torek@horse.ee.lbl.gov (Chris Torek)
  3. Newsgroups: comp.std.c
  4. Subject: does "always append" apply to "a+" mode?
  5. Message-ID: <24992@dog.ee.lbl.gov>
  6. Date: 28 Jul 92 20:04:27 GMT
  7. Organization: Lawrence Berkeley Laboratory, Berkeley
  8. Lines: 39
  9. NNTP-Posting-Host: 128.3.112.15
  10.  
  11. In the section on fopen (4.9.5.3, pp. 130--131), the Standard says:
  12.  
  13.     Opening a file with append mode (|'a'| as the first character in
  14.     the |mode| argument) causes all subsequent writes to the file to be
  15.     forced to the then current end-of-file, regardless of intervening
  16.     calls to the |fseek| function. ...
  17.  
  18.     When a file is opened with update mode (|'+'| as the second or
  19.     third character in the above list of |mode| argument values), both
  20.     input and output may be performed on the associated stream.
  21.     However, [switching directions requires an intervening reposition
  22.     or flush or EOF].
  23.  
  24. To me, it seems clear that a stream opened in "a+" mode can be read at
  25. any arbitrary position, but all writes to that stream are appended to
  26. the underlying file.  There is some dissent, however, on the grounds
  27. that the second paragraph `overrides' the first, i.e., that the first
  28. paragraph does not apply because of the '+' character.
  29.  
  30. As I understand it, the seek/flush/EOF requirement for direction-
  31. changing is a direct result of existing Unix (and possibly other)
  32. implementations, where an intervening seek is required to `sync up'
  33. internal counters and set a read/write stream's mode to
  34. `indeterminate', so that the next getc or putc macro will trigger a
  35. function call, where the new direction will be set.  It is not meant
  36. to imply that seeks have any effect on "a+" mode files.
  37.  
  38. Is this correct?  A number of existing implementations that claim POSIX
  39. conformance (and hence ANSI X3.159-1989 conformance) do NOT always
  40. append with "a+" mode; are they broken?
  41.  
  42. (As an aside, I have an existence proof that the intermediate seek
  43. `feature' is unnecessary, in the form of the 4.3BSD-net.2 stdio.  My
  44. stdio will never allow a getc or putc on an open write- or read-only
  45. stream, whether or not the counters are `synced up'.  All it takes is
  46. two counters, instead of one....)
  47. -- 
  48. In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
  49. Berkeley, CA        Domain:    torek@ee.lbl.gov
  50.