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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
  2. From: torek@horse.ee.lbl.gov (Chris Torek)
  3. Newsgroups: comp.unix.bsd
  4. Subject: Re: STDIO Mode "a+" screwed up
  5. Message-ID: <25009@dog.ee.lbl.gov>
  6. Date: 29 Jul 92 08:04:17 GMT
  7. References: <39897@gremlin.nrtc.northrop.com> <24972@dog.ee.lbl.gov>
  8. Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
  9. Organization: Lawrence Berkeley Laboratory, Berkeley
  10. Lines: 23
  11. NNTP-Posting-Host: 128.3.112.15
  12.  
  13. In article <24972@dog.ee.lbl.gov> I wrote:
  14. [stdio "a+" mode is supposed to work the way it does]
  15. >[The rogue score code] should use "w+" mode.
  16.  
  17. This should be "r+" mode; "w+" would wipe out any previous scores.
  18. Thanks to Andras Radics <andras@cyber.net> for catching this.
  19.  
  20. Of course, r+ mode will not create the file if it does not exist.
  21. (On the other hand, in this case the permissions for the file may
  22. be a problem; some user may run rogue with umask 0777, for instance.)
  23. Perhaps the simplest approach is:
  24.  
  25.     if ((fd = open(path, O_RDWR | O_CREAT, mode)) < 0)
  26.         ... handle open error ...
  27.     (void)fchmod(fd, mode);    /* undo any user umask */
  28.     if ((fp = fdopen(fd, "r+")) == NULL)
  29.         ... handle fopen error ...
  30.  
  31. Since rogue's score file is special, the mode here might legitimately
  32. be something other than 0666, like, oh, say, 0600....
  33. -- 
  34. In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
  35. Berkeley, CA        Domain:    torek@ee.lbl.gov
  36.