diff options
author | Hector Chu <hectorchu@gmail.com> | 2009-11-30 11:53:11 -0800 |
---|---|---|
committer | Hector Chu <hectorchu@gmail.com> | 2009-11-30 11:53:11 -0800 |
commit | 8eabe8208c32050802c06abdc2baf49febf6fb7a (patch) | |
tree | 7ac62e529fdf4675e7449e7171ed7cc0a573e517 /src/lib9 | |
parent | 2c880cf84880cfac9c667f48087c7c30d19b76ba (diff) | |
download | golang-8eabe8208c32050802c06abdc2baf49febf6fb7a.tar.gz |
Ports of lib9, libbio and libmach to Windows.
R=rsc
http://codereview.appspot.com/157159
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/lib9')
-rw-r--r-- | src/lib9/Makefile | 20 | ||||
-rw-r--r-- | src/lib9/_p9dir.c | 39 | ||||
-rw-r--r-- | src/lib9/create.c | 21 | ||||
-rw-r--r-- | src/lib9/dirfwstat.c | 2 | ||||
-rw-r--r-- | src/lib9/dirstat.c | 6 | ||||
-rw-r--r-- | src/lib9/open.c | 27 | ||||
-rw-r--r-- | src/lib9/pipe.c | 39 | ||||
-rw-r--r-- | src/lib9/time.c | 6 | ||||
-rw-r--r-- | src/lib9/win32.c | 26 |
9 files changed, 70 insertions, 116 deletions
diff --git a/src/lib9/Makefile b/src/lib9/Makefile index 6f0739d2c..9038730b1 100644 --- a/src/lib9/Makefile +++ b/src/lib9/Makefile @@ -54,7 +54,6 @@ LIB9OFILES=\ _exits.$O\ argv0.$O\ atoi.$O\ - await.$O\ cleanname.$O\ create.$O\ dirfstat.$O\ @@ -69,23 +68,32 @@ LIB9OFILES=\ exits.$O\ getenv.$O\ getfields.$O\ - getuser.$O\ getwd.$O\ - jmp.$O\ main.$O\ nan.$O\ - notify.$O\ nulldir.$O\ open.$O\ - pipe.$O\ readn.$O\ - rfork.$O\ seek.$O\ strecpy.$O\ sysfatal.$O\ time.$O\ tokenize.$O\ +ifeq ($(GOOS),mingw) +LIB9OFILES+=\ + win32.$O\ + +else +LIB9OFILES+=\ + await.$O\ + getuser.$O\ + jmp.$O\ + notify.$O\ + rfork.$O\ + +endif + OFILES=\ $(LIB9OFILES)\ $(FMTOFILES)\ diff --git a/src/lib9/_p9dir.c b/src/lib9/_p9dir.c index ededa0a92..58c0822a4 100644 --- a/src/lib9/_p9dir.c +++ b/src/lib9/_p9dir.c @@ -29,20 +29,6 @@ THE SOFTWARE. #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> -#include <pwd.h> -#include <grp.h> - -/* - * No need for a real disk size function here: - * the Go build isn't looking at raw disk devices, - * so this avoids portability problems. - */ -#define _HAVEDISKSIZE -static vlong -disksize(int fd, int x) -{ - return 0; -} /* * Caching the last group and passwd looked up is @@ -55,9 +41,6 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * { char *s; char tmp[20]; - static struct group *g; - static struct passwd *p; - static int gid, uid; int sz, fd; fd = -1; @@ -88,11 +71,8 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * sz += strlen(s)+1; /* user */ - if(p == nil || st->st_uid != uid || p->pw_uid != uid){ - snprint(tmp, sizeof tmp, "%d", (int)st->st_uid); - s = tmp; - }else - s = p->pw_name; + snprint(tmp, sizeof tmp, "%d", (int)st->st_uid); + s = tmp; sz += strlen(s)+1; if(d){ if(*str+strlen(s)+1 > estr) @@ -105,11 +85,8 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * } /* group */ - if(g == nil || st->st_gid != gid || g->gr_gid != gid){ - snprint(tmp, sizeof tmp, "%d", (int)st->st_gid); - s = tmp; - }else - s = g->gr_name; + snprint(tmp, sizeof tmp, "%d", (int)st->st_gid); + s = tmp; sz += strlen(s)+1; if(d){ if(*str + strlen(s)+1 > estr) @@ -141,12 +118,16 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * d->mode |= DMDIR; d->qid.type = QTDIR; } +#ifdef S_ISLNK if(S_ISLNK(lst->st_mode)) /* yes, lst not st */ d->mode |= DMSYMLINK; +#endif if(S_ISFIFO(st->st_mode)) d->mode |= DMNAMEDPIPE; +#ifdef S_ISSOCK if(S_ISSOCK(st->st_mode)) d->mode |= DMSOCKET; +#endif if(S_ISBLK(st->st_mode)){ d->mode |= DMDEVICE; d->qid.path = ('b'<<16)|st->st_rdev; @@ -156,12 +137,10 @@ _p9dir(struct stat *lst, struct stat *st, char *name, Dir *d, char **str, char * d->qid.path = ('c'<<16)|st->st_rdev; } /* fetch real size for disks */ -#ifdef _HAVEDISKSIZE if(S_ISBLK(st->st_mode) && (fd = open(name, O_RDONLY)) >= 0){ - d->length = disksize(fd, major(st->st_dev)); + d->length = 0; close(fd); } -#endif #if defined(DIOCGMEDIASIZE) if(isdisk(st)){ int fd; diff --git a/src/lib9/create.c b/src/lib9/create.c index 8e5cbc360..59845ba91 100644 --- a/src/lib9/create.c +++ b/src/lib9/create.c @@ -37,14 +37,11 @@ THE SOFTWARE. int p9create(char *path, int mode, ulong perm) { - int fd, cexec, umode, rclose, lock, rdwr; - struct flock fl; + int fd, umode, rclose, rdwr; rdwr = mode&3; - lock = mode&OLOCK; - cexec = mode&OCEXEC; rclose = mode&ORCLOSE; - mode &= ~(ORCLOSE|OCEXEC|OLOCK); + mode &= ~ORCLOSE; /* XXX should get mode mask right? */ fd = -1; @@ -75,23 +72,11 @@ p9create(char *path, int mode, ulong perm) werrstr("unsupported mode in create"); goto out; } + umode |= O_BINARY; fd = open(path, umode, perm); } out: if(fd >= 0){ - if(lock){ - fl.l_type = (rdwr==OREAD) ? F_RDLCK : F_WRLCK; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - if(fcntl(fd, F_SETLK, &fl) < 0){ - close(fd); - werrstr("lock: %r"); - return -1; - } - } - if(cexec) - fcntl(fd, F_SETFL, FD_CLOEXEC); if(rclose) remove(path); } diff --git a/src/lib9/dirfwstat.c b/src/lib9/dirfwstat.c index 657a98df0..15f1c1252 100644 --- a/src/lib9/dirfwstat.c +++ b/src/lib9/dirfwstat.c @@ -61,10 +61,12 @@ dirfwstat(int fd, Dir *dir) struct timeval tv[2]; ret = 0; +#ifndef __MINGW32__ if(~dir->mode != 0){ if(fchmod(fd, dir->mode) < 0) ret = -1; } +#endif if(~dir->mtime != 0){ tv[0].tv_sec = dir->mtime; tv[0].tv_usec = 0; diff --git a/src/lib9/dirstat.c b/src/lib9/dirstat.c index 5cb6790bc..6c476753b 100644 --- a/src/lib9/dirstat.c +++ b/src/lib9/dirstat.c @@ -39,11 +39,17 @@ dirstat(char *file) Dir *d; char *str; +#ifdef __MINGW32__ + if(stat(file, &st) < 0) + return nil; + lst = st; +#else if(lstat(file, &lst) < 0) return nil; st = lst; if((lst.st_mode&S_IFMT) == S_IFLNK) stat(file, &st); +#endif nstr = _p9dir(&lst, &st, file, nil, nil, nil); d = malloc(sizeof(Dir)+nstr); diff --git a/src/lib9/open.c b/src/lib9/open.c index 1fa3c1bc7..4ac81ba5f 100644 --- a/src/lib9/open.c +++ b/src/lib9/open.c @@ -35,16 +35,13 @@ THE SOFTWARE. int p9open(char *name, int mode) { - int cexec, rclose; - int fd, umode, lock, rdwr; - struct flock fl; + int rclose; + int fd, umode, rdwr; rdwr = mode&3; umode = rdwr; - cexec = mode&OCEXEC; rclose = mode&ORCLOSE; - lock = mode&OLOCK; - mode &= ~(3|OCEXEC|ORCLOSE|OLOCK); + mode &= ~(3|ORCLOSE); if(mode&OTRUNC){ umode |= O_TRUNC; mode ^= OTRUNC; @@ -53,10 +50,6 @@ p9open(char *name, int mode) umode |= O_DIRECT; mode ^= ODIRECT; } - if(mode&ONONBLOCK){ - umode |= O_NONBLOCK; - mode ^= ONONBLOCK; - } if(mode&OAPPEND){ umode |= O_APPEND; mode ^= OAPPEND; @@ -65,21 +58,9 @@ p9open(char *name, int mode) werrstr("mode 0x%x not supported", mode); return -1; } + umode |= O_BINARY; fd = open(name, umode); if(fd >= 0){ - if(lock){ - fl.l_type = (rdwr==OREAD) ? F_RDLCK : F_WRLCK; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; - if(fcntl(fd, F_SETLK, &fl) < 0){ - close(fd); - werrstr("lock: %r"); - return -1; - } - } - if(cexec) - fcntl(fd, F_SETFL, FD_CLOEXEC); if(rclose) remove(name); } diff --git a/src/lib9/pipe.c b/src/lib9/pipe.c deleted file mode 100644 index 0a7d07390..000000000 --- a/src/lib9/pipe.c +++ /dev/null @@ -1,39 +0,0 @@ -/* -Plan 9 from User Space src/lib9/getenv.c -http://code.swtch.com/plan9port/src/tip/src/lib9/getenv.c - -Copyright 2001-2007 Russ Cox. All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -#include <u.h> -#define NOPLAN9DEFINES -#include <libc.h> -#include <sys/socket.h> - -/* - * We use socketpair to get a two-way pipe. - * The pipe still doesn't preserve message boundaries. - * Worse, it cannot be reopened via /dev/fd/NNN on Linux. - */ -int -p9pipe(int fd[2]) -{ - return socketpair(AF_UNIX, SOCK_STREAM, 0, fd); -} diff --git a/src/lib9/time.c b/src/lib9/time.c index ab1b90560..720dd702e 100644 --- a/src/lib9/time.c +++ b/src/lib9/time.c @@ -25,13 +25,18 @@ THE SOFTWARE. #include <u.h> #include <sys/time.h> #include <time.h> +#ifndef __MINGW32__ #include <sys/resource.h> +#endif #define NOPLAN9DEFINES #include <libc.h> long p9times(long *t) { +#ifdef __MINGW32__ + memset(t, 0, 4*sizeof(long)); +#else struct rusage ru, cru; if(getrusage(0, &ru) < 0 || getrusage(-1, &cru) < 0) @@ -41,6 +46,7 @@ p9times(long *t) t[1] = ru.ru_stime.tv_sec*1000 + ru.ru_stime.tv_usec/1000; t[2] = cru.ru_utime.tv_sec*1000 + cru.ru_utime.tv_usec/1000; t[3] = cru.ru_stime.tv_sec*1000 + cru.ru_stime.tv_usec/1000; +#endif /* BUG */ return t[0]+t[1]+t[2]+t[3]; diff --git a/src/lib9/win32.c b/src/lib9/win32.c new file mode 100644 index 000000000..90753bb8d --- /dev/null +++ b/src/lib9/win32.c @@ -0,0 +1,26 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include <u.h> +#include <libc.h> + +int fork() +{ + return -1; +} + +int p9rfork(int flags) +{ + return -1; +} + +Waitmsg *p9wait() +{ + return 0; +} + +int p9waitpid() +{ + return -1; +} |