plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

access.c (523B)


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