1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:44:43 -07:00

os: fix Getenv for Plan 9. Truncate the rightmost char if it is '\0'.

R=mirtchovski, ality, taruti, rsc
CC=golang-dev
https://golang.org/cl/4386046
This commit is contained in:
Yuval Pavel Zholkover 2011-06-08 09:44:03 -04:00 committed by Russ Cox
parent ddde52ae56
commit 6c746328f7

View File

@ -23,13 +23,18 @@ func Getenverror(key string) (value string, err Error) {
} }
defer f.Close() defer f.Close()
var buf [4096]byte l, _ := f.Seek(0, 2)
n, e := f.Read(buf[:len(buf)-1]) f.Seek(0, 0)
buf := make([]byte, l)
n, e := f.Read(buf)
if iserror(e) { if iserror(e) {
return "", ENOENV return "", ENOENV
} }
buf[n] = 0
return string(buf[0:n]), nil if n > 0 && buf[n-1] == 0 {
buf = buf[:n-1]
}
return string(buf), nil
} }
// Getenv retrieves the value of the environment variable named by the key. // Getenv retrieves the value of the environment variable named by the key.
@ -52,7 +57,7 @@ func Setenv(key, value string) Error {
} }
defer f.Close() defer f.Close()
_, e = f.Write(syscall.StringByteSlice(value)) _, e = f.Write([]byte(value))
return nil return nil
} }