Return to BSD News archive
Path: sserve!manuel!munnari.oz.au!hp9000.csc.cuhk.hk!uakari.primate.wisc.edu!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek From: torek@horse.ee.lbl.gov (Chris Torek) Newsgroups: comp.unix.bsd Subject: Re: STDIO Mode "a+" screwed up Message-ID: <25009@dog.ee.lbl.gov> Date: 29 Jul 92 08:04:17 GMT References: <39897@gremlin.nrtc.northrop.com> <24972@dog.ee.lbl.gov> Reply-To: torek@horse.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 23 NNTP-Posting-Host: 128.3.112.15 In article <24972@dog.ee.lbl.gov> I wrote: [stdio "a+" mode is supposed to work the way it does] >[The rogue score code] should use "w+" mode. This should be "r+" mode; "w+" would wipe out any previous scores. Thanks to Andras Radics <andras@cyber.net> for catching this. Of course, r+ mode will not create the file if it does not exist. (On the other hand, in this case the permissions for the file may be a problem; some user may run rogue with umask 0777, for instance.) Perhaps the simplest approach is: if ((fd = open(path, O_RDWR | O_CREAT, mode)) < 0) ... handle open error ... (void)fchmod(fd, mode); /* undo any user umask */ if ((fp = fdopen(fd, "r+")) == NULL) ... handle fopen error ... Since rogue's score file is special, the mode here might legitimately be something other than 0666, like, oh, say, 0600.... -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov