home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 17076 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  2.1 KB

  1. Path: sparky!uunet!think.com!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
  2. From: torek@horse.ee.lbl.gov (Chris Torek)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Appending To A File
  5. Date: 24 Nov 1992 01:48:48 GMT
  6. Organization: Lawrence Berkeley Laboratory, Berkeley
  7. Lines: 40
  8. Message-ID: <27628@dog.ee.lbl.gov>
  9. References: <1992Nov20.192627.8533@nosc.mil>
  10. Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
  11. NNTP-Posting-Host: 128.3.112.15
  12.  
  13. In article <1992Nov20.192627.8533@nosc.mil> mitch@nosc.mil
  14. (Ray Mitchell) writes:
  15. >rewinding, then attempting to write to a file opened in the "a+" mode.
  16.  
  17. [various sample outputs deleted]
  18.  
  19. The UNIX version tested in the original article fails to conform; the
  20. MS-DOS Borland and Microsoft outputs conform to the ANSI standard.
  21.  
  22. >... I guess my question boils down to what the rewind (and I assume
  23. >all the other positioning functions) are supposed to do in the "a+"
  24. >mode.
  25.  
  26. Stdio positioning functions have two effects:
  27.  
  28.     a) They reposition the file for the next input or output
  29.        operation.
  30.     b) They reset `+'-mode files so that the next operation may
  31.        be either input or output.  Once I/O is begun, another file
  32.        position operation is needed to `change directions'.  (Some
  33.        implementations, such as my own, waive the right to demand
  34.        such a positioning operation, but other significant existing
  35.        C libraries required it, so it got put into the ANSI C
  36.        standard.)
  37.  
  38. Now, in the case of `a'ppend mode, all writes are supposed to be
  39. appended to the file, regardless of any intervening fseek, fsetpos,
  40. or rewind operation.  Thus, for "a+" mode, only effect (b) above
  41. is relevant.
  42.  
  43. If you want to append to a file, with the option of replacing the
  44. appended text within the same run, you must open the file in "r+" mode
  45. (or "w+" if it does not yet exist), position to the end with fseek(),
  46. remember that position with fgetpos, append, and then return to it with
  47. fsetpos.  Note that some systems will impose strange restrictions on
  48. `position to the end', such as requiring that `the end' always be a
  49. multiple of 512 bytes.
  50. -- 
  51. In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
  52. Berkeley, CA        Domain:    torek@ee.lbl.gov
  53.