1 fd04aace 2003-11-23 devnull #include <u.h>
2 32f69c36 2003-12-11 devnull #define NOPLAN9DEFINES
3 fd04aace 2003-11-23 devnull #include <libc.h>
4 32f69c36 2003-12-11 devnull #include <sys/stat.h>
7 8ad51794 2004-03-25 devnull p9create(char *path, int mode, ulong perm)
9 32f69c36 2003-12-11 devnull int fd, cexec, umode, rclose;
11 32f69c36 2003-12-11 devnull cexec = mode&OCEXEC;
12 32f69c36 2003-12-11 devnull rclose = mode&ORCLOSE;
13 32f69c36 2003-12-11 devnull mode &= ~(ORCLOSE|OCEXEC);
15 32f69c36 2003-12-11 devnull /* XXX should get mode mask right? */
17 32f69c36 2003-12-11 devnull if(perm&DMDIR){
18 32f69c36 2003-12-11 devnull if(mode != OREAD){
19 32f69c36 2003-12-11 devnull werrstr("bad mode in directory create");
20 32f69c36 2003-12-11 devnull goto out;
22 32f69c36 2003-12-11 devnull if(mkdir(path, perm&0777) < 0)
23 32f69c36 2003-12-11 devnull goto out;
24 32f69c36 2003-12-11 devnull fd = open(path, O_RDONLY);
26 32f69c36 2003-12-11 devnull umode = (mode&3)|O_CREAT|O_TRUNC;
27 32f69c36 2003-12-11 devnull mode &= ~(3|OTRUNC);
28 32f69c36 2003-12-11 devnull if(mode&OEXCL){
29 32f69c36 2003-12-11 devnull umode |= O_EXCL;
30 32f69c36 2003-12-11 devnull mode &= ~OEXCL;
32 32f69c36 2003-12-11 devnull if(mode){
33 32f69c36 2003-12-11 devnull werrstr("unsupported mode in create");
34 32f69c36 2003-12-11 devnull goto out;
36 32f69c36 2003-12-11 devnull fd = open(path, umode, perm);
39 32f69c36 2003-12-11 devnull if(fd >= 0){
40 32f69c36 2003-12-11 devnull if(cexec)
41 32f69c36 2003-12-11 devnull fcntl(fd, F_SETFL, FD_CLOEXEC);
42 32f69c36 2003-12-11 devnull if(rclose)
43 32f69c36 2003-12-11 devnull remove(path);
45 32f69c36 2003-12-11 devnull return fd;