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 00:00:39 -0400	[thread overview]
Message-ID: <ee9e417a0610082100n256719c6j568ce455859414e@mail.gmail.com> (raw)
In-Reply-To: <f1dec573a0466a32a59881314c144e9f@plan9.jp>

> I'm trying to implement output redirection, > and >>.  Truncating
> redirect (>) is easy; just use create(2) whether the file exists or
> no.  The non-truncing option is puzzling me, though.  If the file
> exists, I need to o = open(oname, OWRITE), then seek(o, 0, 2); if the
> file does not exist I need to create it.
>
> How do I check for the existence of a file?  I'm thinking about the
> following code snippet:

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.
Or use create with OEXCL if you really care.

> Of secondary interest: Not that this is production code, but should I
> be concerned about race conditions where the file is created by
> somebody else between the failed open(2) and the create(2)?

Nope.  This is Plan 9.  Everyone has private /tmp directories.

> Of tertiary interest: Is there a general use for a library function
> complain() that behaves identically to sysfatal(2) except for not
> terminating the program?

Probably not.  The interesting part of sysfatal is the
terminating the program, not the printing of the error.

Russ


  reply	other threads:[~2006-10-09  4:00 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 [this message]
2006-10-09  6:09   ` Joel “chesky” Salomon
2006-10-09 15:57     ` Russ Cox
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=ee9e417a0610082100n256719c6j568ce455859414e@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).