2004-04-29 17:13:24 +00:00
|
|
|
#define _GNU_SOURCE /* for Linux O_DIRECT */
|
2003-12-11 17:50:28 +00:00
|
|
|
#include <u.h>
|
|
|
|
#define NOPLAN9DEFINES
|
|
|
|
#include <libc.h>
|
2004-05-14 20:19:53 +00:00
|
|
|
#ifndef O_DIRECT
|
|
|
|
#define O_DIRECT 0
|
|
|
|
#endif
|
2003-12-11 17:50:28 +00:00
|
|
|
|
|
|
|
int
|
2004-03-25 23:03:57 +00:00
|
|
|
p9open(char *name, int mode)
|
2003-12-11 17:50:28 +00:00
|
|
|
{
|
|
|
|
int cexec, rclose;
|
|
|
|
int fd, umode;
|
|
|
|
|
|
|
|
umode = mode&3;
|
|
|
|
cexec = mode&OCEXEC;
|
|
|
|
rclose = mode&ORCLOSE;
|
|
|
|
mode &= ~(3|OCEXEC|ORCLOSE);
|
|
|
|
if(mode&OTRUNC){
|
|
|
|
umode |= O_TRUNC;
|
|
|
|
mode ^= OTRUNC;
|
|
|
|
}
|
2004-04-29 17:13:24 +00:00
|
|
|
if(mode&ODIRECT){
|
|
|
|
umode |= O_DIRECT;
|
|
|
|
mode ^= ODIRECT;
|
|
|
|
}
|
2003-12-11 17:50:28 +00:00
|
|
|
if(mode){
|
2004-05-14 19:45:23 +00:00
|
|
|
werrstr("mode 0x%x not supported", mode);
|
2003-12-11 17:50:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fd = open(name, umode);
|
|
|
|
if(fd >= 0){
|
|
|
|
if(cexec)
|
|
|
|
fcntl(fd, F_SETFL, FD_CLOEXEC);
|
|
|
|
if(rclose)
|
|
|
|
remove(name);
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|