Path: blob/main/vendor/golang.org/x/sys/windows/env_windows.go
2880 views
// Copyright 2010 The Go Authors. All rights reserved.1// Use of this source code is governed by a BSD-style2// license that can be found in the LICENSE file.34// Windows environment variables.56package windows78import (9"syscall"10"unsafe"11)1213func Getenv(key string) (value string, found bool) {14return syscall.Getenv(key)15}1617func Setenv(key, value string) error {18return syscall.Setenv(key, value)19}2021func Clearenv() {22syscall.Clearenv()23}2425func Environ() []string {26return syscall.Environ()27}2829// Returns a default environment associated with the token, rather than the current30// process. If inheritExisting is true, then this environment also inherits the31// environment of the current process.32func (token Token) Environ(inheritExisting bool) (env []string, err error) {33var block *uint1634err = CreateEnvironmentBlock(&block, token, inheritExisting)35if err != nil {36return nil, err37}38defer DestroyEnvironmentBlock(block)39size := unsafe.Sizeof(*block)40for *block != 0 {41// find NUL terminator42end := unsafe.Pointer(block)43for *(*uint16)(end) != 0 {44end = unsafe.Add(end, size)45}4647entry := unsafe.Slice(block, (uintptr(end)-uintptr(unsafe.Pointer(block)))/size)48env = append(env, UTF16ToString(entry))49block = (*uint16)(unsafe.Add(end, size))50}51return env, nil52}5354func Unsetenv(key string) error {55return syscall.Unsetenv(key)56}575859