From: "Russ Cox" <rsc@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] what a mess the Unix world has become
Date: Mon, 10 Feb 2003 06:58:50 -0500 [thread overview]
Message-ID: <43f501b9d5e342678de110cc46b75ef9@plan9.bell-labs.com> (raw)
In-Reply-To: <3E46ACD7.50802@null.net>
> What OS facility is there for determining whether a file
> would be writable without actually modifying the file?
umm, open(2)? this doesn't handle the AEXEC|AREAD
or AEXEC|AWRITE cases particularly well, and it's not
as fast as traditional access, but it gives good answers.
#include <u.h>
#include <libc.h>
int
access(char *name, int mode)
{
int fd;
Dir *db;
static char omode[] = {
0,
OEXEC,
OWRITE,
ORDWR,
OREAD,
OEXEC, /* only approximate */
ORDWR,
ORDWR /* only approximate */
};
if(mode == AEXIST){
db = dirstat(name);
free(db);
if(db != nil)
return 0;
return -1;
}
fd = open(name, omode[mode&7]);
if(fd >= 0){
close(fd);
return 0;
}
return -1;
}
next prev parent reply other threads:[~2003-02-10 11:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-09 10:05 Aharon Robbins
2003-02-09 19:48 ` Mike Haertel
2003-02-10 9:00 ` [9fans] mpg123 Conor Williams
2003-02-10 12:02 ` Russ Cox
2003-02-10 14:14 ` Nigel Roles
2003-02-10 14:34 ` Fco.J.Ballesteros
2003-02-10 14:53 ` Axel Belinfante
2003-02-10 15:05 ` Fco.J.Ballesteros
2003-02-10 15:53 ` Conor Williams
2003-02-10 16:41 ` Fco.J.Ballesteros
2003-02-11 10:19 ` Conor Williams
2003-02-11 11:26 ` nigel
2003-02-13 9:02 ` Conor Williams
2003-02-10 18:13 ` Tad Hunt
2003-02-10 10:04 ` [9fans] what a mess the Unix world has become Douglas A. Gwyn
2003-02-10 11:58 ` Russ Cox [this message]
2003-02-10 15:20 ` Ronald G. Minnich
2003-02-11 9:29 ` Douglas A. Gwyn
2003-02-11 10:25 ` Geoff Collyer
2003-02-10 16:19 C H Forsyth
2003-02-10 20:26 ` Ronald G. Minnich
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=43f501b9d5e342678de110cc46b75ef9@plan9.bell-labs.com \
--to=rsc@plan9.bell-labs.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).