diff options
Diffstat (limited to 'src/pkg/syscall/env_windows.go')
-rw-r--r-- | src/pkg/syscall/env_windows.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/pkg/syscall/env_windows.go b/src/pkg/syscall/env_windows.go index 8308f10a2..39bd5022e 100644 --- a/src/pkg/syscall/env_windows.go +++ b/src/pkg/syscall/env_windows.go @@ -12,14 +12,18 @@ import ( ) func Getenv(key string) (value string, found bool) { + keyp, err := UTF16PtrFromString(key) + if err != nil { + return "", false + } b := make([]uint16, 100) - n, e := GetEnvironmentVariable(StringToUTF16Ptr(key), &b[0], uint32(len(b))) + n, e := GetEnvironmentVariable(keyp, &b[0], uint32(len(b))) if n == 0 && e == ERROR_ENVVAR_NOT_FOUND { return "", false } if n > uint32(len(b)) { b = make([]uint16, n) - n, e = GetEnvironmentVariable(StringToUTF16Ptr(key), &b[0], uint32(len(b))) + n, e = GetEnvironmentVariable(keyp, &b[0], uint32(len(b))) if n > uint32(len(b)) { n = 0 } @@ -32,10 +36,18 @@ func Getenv(key string) (value string, found bool) { func Setenv(key, value string) error { var v *uint16 + var err error if len(value) > 0 { - v = StringToUTF16Ptr(value) + v, err = UTF16PtrFromString(value) + if err != nil { + return err + } + } + keyp, err := UTF16PtrFromString(key) + if err != nil { + return err } - e := SetEnvironmentVariable(StringToUTF16Ptr(key), v) + e := SetEnvironmentVariable(keyp, v) if e != nil { return e } |