1 #include <u.h> 2 #include <libc.h> 3 4 int access(char * name,int mode)5access(char *name, int mode) 6 { 7 int fd; 8 Dir *db; 9 static char omode[] = { 10 0, 11 OEXEC, 12 OWRITE, 13 ORDWR, 14 OREAD, 15 OEXEC, /* only approximate */ 16 ORDWR, 17 ORDWR /* only approximate */ 18 }; 19 20 if(mode == AEXIST){ 21 db = dirstat(name); 22 free(db); 23 if(db != nil) 24 return 0; 25 return -1; 26 } 27 fd = open(name, omode[mode&7]); 28 if(fd >= 0){ 29 close(fd); 30 return 0; 31 } 32 return -1; 33 } 34