mirror of
https://github.com/golang/go
synced 2024-11-21 16:14:42 -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:
parent
ddde52ae56
commit
6c746328f7
@ -23,13 +23,18 @@ func Getenverror(key string) (value string, err Error) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var buf [4096]byte
|
||||
n, e := f.Read(buf[:len(buf)-1])
|
||||
l, _ := f.Seek(0, 2)
|
||||
f.Seek(0, 0)
|
||||
buf := make([]byte, l)
|
||||
n, e := f.Read(buf)
|
||||
if iserror(e) {
|
||||
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.
|
||||
@ -52,7 +57,7 @@ func Setenv(key, value string) Error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, e = f.Write(syscall.StringByteSlice(value))
|
||||
_, e = f.Write([]byte(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user