Commit 6c746328 authored by Yuval Pavel Zholkover's avatar Yuval Pavel Zholkover Committed by Russ Cox

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
parent ddde52ae
...@@ -23,13 +23,18 @@ func Getenverror(key string) (value string, err Error) { ...@@ -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 { ...@@ -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
} }
......
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