// Setenv sets the value of the environment variable named by the key. // It returns an Error, if any. func Setenv(key, value string) Error { var v *uint16 if len(value) > 0 { v = syscall.StringToUTF16Ptr(value) } ok, e := syscall.SetEnvironmentVariable(syscall.StringToUTF16Ptr(key), v) if !ok { return NewSyscallError("SetEnvironmentVariable", e) } return nil }
// os.Clearenv() doesn't actually unset variables on Windows // See: https://github.com/golang/go/issues/17902 func clearenv() { for _, s := range os.Environ() { for j := 1; j < len(s); j++ { if s[j] == '=' { keyp, _ := syscall.UTF16PtrFromString(s[0:j]) syscall.SetEnvironmentVariable(keyp, nil) break } } } }