Blob
1 #include <u.h>2 #define NOPLAN9DEFINES3 #include <libc.h>5 int6 p9open(char *name, int mode)7 {8 int cexec, rclose;9 int fd, umode;11 umode = mode&3;12 cexec = mode&OCEXEC;13 rclose = mode&ORCLOSE;14 mode &= ~(3|OCEXEC|ORCLOSE);15 if(mode&OTRUNC){16 umode |= O_TRUNC;17 mode ^= OTRUNC;18 }19 if(mode){20 werrstr("mode not supported");21 return -1;22 }23 fd = open(name, umode);24 if(fd >= 0){25 if(cexec)26 fcntl(fd, F_SETFL, FD_CLOEXEC);27 if(rclose)28 remove(name);29 }30 return fd;31 }