From: Anthony Martin Date: Mon, 17 Dec 2012 16:07:40 +0000 (-0500) Subject: runtime: implement getenv for Plan 9 X-Git-Tag: go1.1rc2~1606 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=432f18221fa77b814854053e751c125c9920886c;p=gostls13.git runtime: implement getenv for Plan 9 With this change the runtime can now read GOMAXPROCS, GOGC, etc. I'm not quite sure how we missed this. R=seed, lucio.dere, rsc CC=golang-dev https://golang.org/cl/6935062 --- diff --git a/src/pkg/runtime/env_plan9.c b/src/pkg/runtime/env_plan9.c new file mode 100644 index 0000000000..848d733037 --- /dev/null +++ b/src/pkg/runtime/env_plan9.c @@ -0,0 +1,33 @@ +// Copyright 2012 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 "runtime.h" +#include "os_GOOS.h" + +byte* +runtime·getenv(int8 *s) +{ + int32 fd, len, n, r; + byte file[128]; + byte *p; + + len = runtime·findnull((byte*)s); + if(len > sizeof file-6) + return nil; + + runtime·memclr(file, sizeof file); + runtime·memmove((void*)file, (void*)"/env/", 5); + runtime·memmove((void*)(file+5), (void*)s, len); + + fd = runtime·open(file, OREAD); + if(fd < 0) + return nil; + n = runtime·seek(fd, 0, 2); + p = runtime·malloc(n+1); + r = runtime·pread(fd, p, n, 0); + runtime·close(fd); + if(r < 0) + return nil; + return p; +} diff --git a/src/pkg/runtime/env_posix.c b/src/pkg/runtime/env_posix.c new file mode 100644 index 0000000000..b4342d37b6 --- /dev/null +++ b/src/pkg/runtime/env_posix.c @@ -0,0 +1,61 @@ +// Copyright 2012 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. + +// +build darwin freebsd linux netbsd openbsd windows + +#include "runtime.h" + +Slice syscall·envs; + +byte* +runtime·getenv(int8 *s) +{ + int32 i, j, len; + byte *v, *bs; + String* envv; + int32 envc; + + bs = (byte*)s; + len = runtime·findnull(bs); + envv = (String*)syscall·envs.array; + envc = syscall·envs.len; + for(i=0; i(SB),7,$0 + MOVQ $0x8000, AX + MOVQ $39, BP + SYSCALL + RET + +// int64 seek(int32, int64, int32) +TEXT runtime·seek(SB),7,$56 + LEAQ new+48(SP), CX + MOVQ CX, 0(SP) + MOVQ fd+0(FP), CX + MOVQ CX, 8(SP) + MOVQ off+8(FP), CX + MOVQ CX, 16(SP) + MOVQ whence+16(FP), CX + MOVQ CX, 24(SP) + CALL _seek<>(SB) + CMPL AX, $0 + JGE 2(PC) + MOVQ $-1, new+48(SP) + MOVQ new+48(SP), AX + RET + TEXT runtime·close(SB),7,$0 MOVQ $0x8000, AX MOVQ $4, BP