*BSD News Article 2622


Return to BSD News archive

Path: sserve!manuel!munnari.oz.au!network.ucsd.edu!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
Date: 28 Jul 1992 00:47:22 GMT
Organization: Lawrence Berkeley Laboratory, Berkeley
Lines: 27
Message-ID: <24972@dog.ee.lbl.gov>
References: <39897@gremlin.nrtc.northrop.com>
Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
NNTP-Posting-Host: 128.3.112.15

In article <39897@gremlin.nrtc.northrop.com> dec@lazarus.nrtc.northrop.com
(Dwight E. Cass) writes:
>   I have just spent the weekend trying to find out why rogue crashes
>when it attempts to update its score file and have found the problem:

>   In: /usr/src/lib/libc/stdio/flags.c - Mode "a+" translates to an
>       open flag with O_APPEND (in __sflags()).  This means that if
>       you seek the file to the beginning and start writting, all the
>       written will be APPENDED to the end of the file - rather than
>       updating the top of the file as specified by the plus sign.

This is not a bug.  ANSI C standard, section 4.9.5.3, pp. 126--127,
l. 39 ff.:

	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*.

[emphasis mine]

>   What's the cure - ouch.

Fix rogue.  It should use "w+" mode.
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov