libc: rewrite access()
This commit is contained in:
parent
b862596737
commit
66373243bd
@ -572,6 +572,7 @@ extern void freenetconninfo(NetConnInfo*);
|
|||||||
#define AREAD 4 /* read access */
|
#define AREAD 4 /* read access */
|
||||||
#define AWRITE 2 /* write access */
|
#define AWRITE 2 /* write access */
|
||||||
#define AEXEC 1 /* execute access */
|
#define AEXEC 1 /* execute access */
|
||||||
|
#define AMASK (AEXIST|AREAD|AWRITE|AEXEC)
|
||||||
|
|
||||||
/* Segattch */
|
/* Segattch */
|
||||||
#define SG_RONLY 0040 /* read only */
|
#define SG_RONLY 0040 /* read only */
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the UCB release of Plan 9. It is subject to the license
|
* This file is part of Jehanne.
|
||||||
* terms in the LICENSE file found in the top-level directory of this
|
*
|
||||||
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
|
* Copyright (C) 2016 Giacomo Tesio <giacomo@tesio.it>
|
||||||
* part of the UCB release of Plan 9, including this file, may be copied,
|
*
|
||||||
* modified, propagated, or distributed except according to the terms contained
|
* Jehanne is free software: you can redistribute it and/or modify
|
||||||
* in the LICENSE file.
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 2 of the License.
|
||||||
|
*
|
||||||
|
* Jehanne is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
@ -14,27 +23,19 @@ int
|
|||||||
access(const char *name, int mode)
|
access(const char *name, int mode)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
Dir *db;
|
|
||||||
|
|
||||||
static char omode[] = {
|
static char omode[] = {
|
||||||
0,
|
OSTAT,
|
||||||
OEXEC,
|
OEXEC,
|
||||||
OWRITE,
|
OWRITE,
|
||||||
ORDWR,
|
ORDWR,
|
||||||
OREAD,
|
OREAD,
|
||||||
OEXEC, /* only approximate */
|
OEXEC, /* 5=4+1 READ|EXEC, EXEC is enough */
|
||||||
ORDWR,
|
ORDWR,
|
||||||
ORDWR /* only approximate */
|
ORDWR /* 7=4+2+1 READ|WRITE|EXEC, ignore EXEC */
|
||||||
};
|
};
|
||||||
|
|
||||||
if(mode == AEXIST){
|
fd = open(name, omode[mode&AMASK]);
|
||||||
db = dirstat(name);
|
|
||||||
free(db);
|
|
||||||
if(db != nil)
|
|
||||||
return 0;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fd = open(name, omode[mode&7]);
|
|
||||||
if(fd >= 0){
|
if(fd >= 0){
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user