summaryrefslogtreecommitdiffstats
path: root/src/lib9/create.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-12-11 17:48:38 +0000
committerrsc <devnull@localhost>2003-12-11 17:48:38 +0000
commit32f69c36e0eec1227934bbd34854bfebd88686f2 (patch)
tree1587e9de84816b77168afa81c1594cc686809910 /src/lib9/create.c
parentac244f8d287a6119155ea672c8fd13c487c5e4c7 (diff)
downloadplan9port-32f69c36e0eec1227934bbd34854bfebd88686f2.tar.gz
plan9port-32f69c36e0eec1227934bbd34854bfebd88686f2.zip
Add support for user-level 9P servers/clients and various bug fixes to go with them.
Diffstat (limited to 'src/lib9/create.c')
-rw-r--r--src/lib9/create.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/lib9/create.c b/src/lib9/create.c
index abef0c35..bdad5f6a 100644
--- a/src/lib9/create.c
+++ b/src/lib9/create.c
@@ -1,8 +1,54 @@
#include <u.h>
+#define NOPLAN9DEFINES
#include <libc.h>
+#include <sys/stat.h>
+
+extern char *_p9translate(char*);
int
-create(char *path, int mode, ulong perm)
+p9create(char *xpath, int mode, ulong perm)
{
- return open(path, mode|O_CREAT|O_TRUNC, perm);
+ int fd, cexec, umode, rclose;
+ char *path;
+
+ if((path = _p9translate(xpath)) == nil)
+ return -1;
+
+ cexec = mode&OCEXEC;
+ rclose = mode&ORCLOSE;
+ mode &= ~(ORCLOSE|OCEXEC);
+
+ /* XXX should get mode mask right? */
+ fd = -1;
+ if(perm&DMDIR){
+ if(mode != OREAD){
+ werrstr("bad mode in directory create");
+ goto out;
+ }
+ if(mkdir(path, perm&0777) < 0)
+ goto out;
+ fd = open(path, O_RDONLY);
+ }else{
+ umode = (mode&3)|O_CREAT|O_TRUNC;
+ mode &= ~(3|OTRUNC);
+ if(mode&OEXCL){
+ umode |= O_EXCL;
+ mode &= ~OEXCL;
+ }
+ if(mode){
+ werrstr("unsupported mode in create");
+ goto out;
+ }
+ fd = open(path, umode, perm);
+ }
+out:
+ if(fd >= 0){
+ if(cexec)
+ fcntl(fd, F_SETFL, FD_CLOEXEC);
+ if(rclose)
+ remove(path);
+ }
+ if(path != xpath)
+ free(path);
+ return fd;
}