Blob


1 #include <u.h>
2 #define NOPLAN9DEFINES
3 #include <libc.h>
5 extern char* _p9translate(char*);
7 int
8 p9open(char *xname, int mode)
9 {
10 char *name;
11 int cexec, rclose;
12 int fd, umode;
14 umode = mode&3;
15 cexec = mode&OCEXEC;
16 rclose = mode&ORCLOSE;
17 mode &= ~(3|OCEXEC|ORCLOSE);
18 if(mode&OTRUNC){
19 umode |= O_TRUNC;
20 mode ^= OTRUNC;
21 }
22 if(mode){
23 werrstr("mode not supported");
24 return -1;
25 }
26 if((name = _p9translate(xname)) == nil)
27 return -1;
28 fd = open(name, umode);
29 if(fd >= 0){
30 if(cexec)
31 fcntl(fd, F_SETFL, FD_CLOEXEC);
32 if(rclose)
33 remove(name);
34 }
35 if(name != xname)
36 free(name);
37 return fd;
38 }