Blob
1 #define _GNU_SOURCE /* for Linux O_DIRECT */2 #include <u.h>3 #define NOPLAN9DEFINES4 #include <libc.h>5 #ifndef O_DIRECT6 #define O_DIRECT 07 #endif9 int10 p9open(char *name, int mode)11 {12 int cexec, rclose;13 int fd, umode;15 umode = mode&3;16 cexec = mode&OCEXEC;17 rclose = mode&ORCLOSE;18 mode &= ~(3|OCEXEC|ORCLOSE);19 if(mode&OTRUNC){20 umode |= O_TRUNC;21 mode ^= OTRUNC;22 }23 if(mode&ODIRECT){24 umode |= O_DIRECT;25 mode ^= ODIRECT;26 }27 if(mode){28 werrstr("mode 0x%x not supported", mode);29 return -1;30 }31 fd = open(name, umode);32 if(fd >= 0){33 if(cexec)34 fcntl(fd, F_SETFL, FD_CLOEXEC);35 if(rclose)36 remove(name);37 }38 return fd;39 }