9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] non-truncating create
Date: Mon,  9 Oct 2006 11:57:21 -0400	[thread overview]
Message-ID: <ee9e417a0610090857y40e2a25bic2ab448767cef83c@mail.gmail.com> (raw)
In-Reply-To: <49c8e5f6ae1f50391b40e6465b4a8818@plan9.jp>

Rc says something like:

if ((fd = open(file, OWRITE)) < 0 && (fd = 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 <JoelCSalomon@gmail.com> 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 = create(oname, omode|OEXCL, ~0);     /* fails if file exists */
>         if(o < 0)
>                 o = 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ñana.
>
> Thanks for the assist.
>
> --Joel
>
>


  reply	other threads:[~2006-10-09 15:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-09  3:13 Joel “chesky” Salomon
2006-10-09  4:00 ` Russ Cox
2006-10-09  6:09   ` Joel “chesky” Salomon
2006-10-09 15:57     ` Russ Cox [this message]
2006-10-09  4:01 ` Felipe Bichued
2006-10-09  5:39   ` Joel Salomon
2006-10-09  3:13 Joel “chesky” Salomon
2006-10-09  3:13 Joel “chesky” Salomon
2006-10-09  6:46 Joel “chesky” Salomon
2006-10-09  7:30 ` Steve Simon
2006-10-09 22:38 G. David Butler
2006-10-09 23:36 ` Joel Salomon
2006-10-10  0:03 ` Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee9e417a0610090857y40e2a25bic2ab448767cef83c@mail.gmail.com \
    --to=rsc@swtch.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).