Commit 20d9cc4b authored by David du Colombier's avatar David du Colombier Committed by Russ Cox

runtime: fix gogetenv on Plan 9

LGTM=rsc
R=rsc, ality
CC=golang-codereviews
https://golang.org/cl/137030043
parent 649c8353
...@@ -30,21 +30,11 @@ func gogetenv(key string) string { ...@@ -30,21 +30,11 @@ func gogetenv(key string) string {
if fd < 0 { if fd < 0 {
return "" return ""
} }
n := seek(fd, 0, 2) n := seek(fd, 0, 2) - 1
var p unsafe.Pointer p := make([]byte, n)
// Be sure not to allocate for $GOTRACEBACK. r := pread(fd, unsafe.Pointer(&p[0]), int32(n), 0)
if key == "GOTRACEBACK" {
if n >= 128 {
return ""
}
p = unsafe.Pointer(&tracebackbuf[0])
} else {
p = gomallocgc(uintptr(n+1), nil, 0)
}
r := pread(fd, p, int32(n), 0)
close(fd) close(fd)
if r < 0 { if r < 0 {
return "" return ""
...@@ -52,7 +42,7 @@ func gogetenv(key string) string { ...@@ -52,7 +42,7 @@ func gogetenv(key string) string {
var s string var s string
sp := (*_string)(unsafe.Pointer(&s)) sp := (*_string)(unsafe.Pointer(&s))
sp.str = (*byte)(p) sp.str = &p[0]
sp.len = int(r) sp.len = int(r)
return s return s
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment