...
1
2
3
4
5
6
7 package windows
8
9 import (
10 "syscall"
11 "unsafe"
12 )
13
14 func Getenv(key string) (value string, found bool) {
15 return syscall.Getenv(key)
16 }
17
18 func Setenv(key, value string) error {
19 return syscall.Setenv(key, value)
20 }
21
22 func Clearenv() {
23 syscall.Clearenv()
24 }
25
26 func Environ() []string {
27 return syscall.Environ()
28 }
29
30
31
32
33 func (token Token) Environ(inheritExisting bool) (env []string, err error) {
34 var block *uint16
35 err = CreateEnvironmentBlock(&block, token, inheritExisting)
36 if err != nil {
37 return nil, err
38 }
39 defer DestroyEnvironmentBlock(block)
40 size := unsafe.Sizeof(*block)
41 for *block != 0 {
42
43 end := unsafe.Pointer(block)
44 for *(*uint16)(end) != 0 {
45 end = unsafe.Add(end, size)
46 }
47
48 entry := unsafe.Slice(block, (uintptr(end)-uintptr(unsafe.Pointer(block)))/size)
49 env = append(env, UTF16ToString(entry))
50 block = (*uint16)(unsafe.Add(end, size))
51 }
52 return env, nil
53 }
54
55 func Unsetenv(key string) error {
56 return syscall.Unsetenv(key)
57 }
58
View as plain text