Commit b243d57e authored by Alex Brainman's avatar Alex Brainman

os: preserve "=C:" like env variables in env block on windows and bug fix in Clearenv()

R=rsc
CC=golang-dev
https://golang.org/cl/1995043
parent 30ab8cf7
...@@ -60,9 +60,13 @@ func Setenv(key, value string) Error { ...@@ -60,9 +60,13 @@ func Setenv(key, value string) Error {
// Clearenv deletes all environment variables. // Clearenv deletes all environment variables.
func Clearenv() { func Clearenv() {
for _, s := range Environ() { for _, s := range Environ() {
for j := 0; j < len(s); j++ { // Environment variables can begin with =
// so start looking for the separator = at j=1.
// http://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx
for j := 1; j < len(s); j++ {
if s[j] == '=' { if s[j] == '=' {
Setenv(s[0:j], "") Setenv(s[0:j], "")
break
} }
} }
} }
...@@ -83,18 +87,15 @@ func Environ() []string { ...@@ -83,18 +87,15 @@ func Environ() []string {
if i <= from { if i <= from {
break break
} }
// skip anything that starts with '=' if len(r) == cap(r) {
if p[from] != '=' { nr := make([]string, len(r), 2*len(r))
if len(r) == cap(r) { for k := 0; k < len(r); k++ {
nr := make([]string, len(r), 2*len(r)) nr[k] = r[k]
for k := 0; k < len(r); k++ {
nr[k] = r[k]
}
r = nr
} }
r = r[0 : len(r)+1] r = nr
r[len(r)-1] = string(utf16.Decode(p[from:i]))
} }
r = r[0 : len(r)+1]
r[len(r)-1] = string(utf16.Decode(p[from:i]))
from = i + 1 from = i + 1
} }
} }
......
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