From e5888a1ffdae813d7575f5fb02275c6bb07e5199 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Wed, 30 Mar 2011 15:46:40 +0300 Subject: Import sources from 2011-03-30 iso image --- sys/src/ape/lib/ap/plan9/open.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 sys/src/ape/lib/ap/plan9/open.c (limited to 'sys/src/ape/lib/ap/plan9/open.c') diff --git a/sys/src/ape/lib/ap/plan9/open.c b/sys/src/ape/lib/ap/plan9/open.c new file mode 100755 index 000000000..1cfe0d6b5 --- /dev/null +++ b/sys/src/ape/lib/ap/plan9/open.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include "lib.h" +#include +#include "sys9.h" + +/* + * O_NOCTTY has no effect + */ +int +open(const char *path, int flags, ...) +{ + int n; + long f; + int mode; + Fdinfo *fi; + va_list va; + struct stat sbuf; + + f = flags&O_ACCMODE; + if(flags&O_CREAT){ + if(access(path, 0) >= 0){ + if(flags&O_EXCL){ + errno = EEXIST; + return -1; + }else{ + if((flags&O_TRUNC)&&(flags&(O_RDWR|O_WRONLY))) + f |= 16; + n = _OPEN(path, f); + } + }else{ + va_start(va, flags); + mode = va_arg(va, int); + va_end(va); + n = _CREATE(path, f, mode&0777); + } + if(n < 0) + _syserrno(); + }else{ + if((flags&O_TRUNC)&&(flags&(O_RDWR|O_WRONLY))) + f |= 16; + n = _OPEN(path, f); + if(n < 0) + _syserrno(); + } + if(n >= 0){ + fi = &_fdinfo[n]; + fi->flags = FD_ISOPEN; + fi->oflags = flags&(O_ACCMODE|O_NONBLOCK|O_APPEND); + fi->uid = -2; + fi->gid = -2; + fi->name = malloc(strlen(path)+1); + if(fi->name) + strcpy(fi->name, path); + if(fi->oflags&O_APPEND) + _SEEK(n, 0, 2); + } + return n; +} -- cgit v1.2.3