Commit 04b405c7 authored by Alex Brainman's avatar Alex Brainman

syscall: handle empty environment variable values properly on windows

Setenv("AN_ENV_VAR", "") deletes AN_ENV_VAR instead of setting it
to "" at this moment. Also Getenv("AN_ENV_VAR") returns "not found",
if AN_ENV_VAR is "". Change it, so they behave like unix.

Fixes #5610

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10594043
parent d9f5c64f
......@@ -28,20 +28,13 @@ func Getenv(key string) (value string, found bool) {
n = 0
}
}
if n == 0 {
return "", false
}
return string(utf16.Decode(b[0:n])), true
}
func Setenv(key, value string) error {
var v *uint16
var err error
if len(value) > 0 {
v, err = UTF16PtrFromString(value)
if err != nil {
return err
}
v, err := UTF16PtrFromString(value)
if err != nil {
return err
}
keyp, err := UTF16PtrFromString(key)
if err != nil {
......
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package syscall_test
import (
"syscall"
"testing"
)
func testSetGetenv(t *testing.T, key, value string) {
err := syscall.Setenv(key, value)
if err != nil {
t.Fatalf("Setenv failed to set %q: %v", value, err)
}
newvalue, found := syscall.Getenv(key)
if !found {
t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
}
if newvalue != value {
t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
}
}
func TestEnv(t *testing.T) {
testSetGetenv(t, "TESTENV", "AVALUE")
// make sure TESTENV gets set to "", not deleted
testSetGetenv(t, "TESTENV", "")
}
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