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