From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Mon, 9 Oct 2006 11:57:21 -0400 From: "Russ Cox" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu> Subject: Re: [9fans] non-truncating create In-Reply-To: <49c8e5f6ae1f50391b40e6465b4a8818@plan9.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <49c8e5f6ae1f50391b40e6465b4a8818@plan9.jp> Topicbox-Message-UUID: c7624c6e-ead1-11e9-9d60-3106f5b1d025 Rc says something like: if ((fd =3D open(file, OWRITE)) < 0 && (fd =3D create(file, OWRITE, 0666)) = < 0) { complain(...); return; } seek(fd, 0, 2); You don't really mean ~0 as the argument to create. Russ On 10/9/06, Joel "chesky" Salomon wrote: > > Rc just tries the open, and if that fails, tries the create. > > It doesn't even bother looking at the error code. > > If the open failed due to permissions, so will the create. > > Drawterm barfed on me and I lost the bit of code this suggested; when > I tried to recreate it I ended up checking for OTRUNC a few times. > Not pretty. > > > Or use create with OEXCL if you really care. > > Sort of the way create(2) calls create(5) first, then open(5) if that > failed? My code now looks like: > o =3D create(oname, omode|OEXCL, ~0); /* fails if file exists= */ > if(o < 0) > o =3D open(oname, omode); > if(o < 0){ > complain("can't open %s for writing: %r", oname); > return; > } > which has no special-case code depending on OTRUNC being set or no. > > I suppose I ought to look at /sys/src/cmd/rc to see how it's really > done. Ma=F1ana. > > Thanks for the assist. > > --Joel > >