From mboxrd@z Thu Jan 1 00:00:00 1970 From: "G. David Butler" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu> Message-ID: Date: Mon, 9 Oct 2006 22:38:47 +0000 Subject: Re: [9fans] non-truncating create MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Topicbox-Message-UUID: c77c1bd0-ead1-11e9-9d60-3106f5b1d025 And if you are interested in a much deeper discussion, look at the archiv= es from 1999. >-----Original Message----- >From: Russ Cox [mailto:rsc@swtch.com] >Sent: Monday, October 9, 2006 10:57 AM >To: 'Fans of the OS Plan 9 from Bell Labs' >Subject: Re: [9fans] non-truncating create > >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 exi= sts */ >> 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 >> >> >