Source file
src/runtime/env_posix.go
1
2
3
4
5
6
7 package runtime
8
9 import "unsafe"
10
11 func gogetenv(key string) string {
12 env := environ()
13 if env == nil {
14 throw("getenv before env init")
15 }
16 for _, s := range env {
17 if len(s) > len(key) && s[len(key)] == '=' && envKeyEqual(s[:len(key)], key) {
18 return s[len(key)+1:]
19 }
20 }
21 return ""
22 }
23
24
25
26 func envKeyEqual(a, b string) bool {
27 if GOOS == "windows" {
28 for i := 0; i < len(a); i++ {
29 ca, cb := a[i], b[i]
30 if ca == cb || lowerASCII(ca) == lowerASCII(cb) {
31 continue
32 }
33 return false
34 }
35 return true
36 }
37 return a == b
38 }
39
40 func lowerASCII(c byte) byte {
41 if 'A' <= c && c <= 'Z' {
42 return c + ('a' - 'A')
43 }
44 return c
45 }
46
47 var _cgo_setenv unsafe.Pointer
48 var _cgo_unsetenv unsafe.Pointer
49
50
51
52
53 func syscall_setenv_c(k string, v string) {
54 if _cgo_setenv == nil {
55 return
56 }
57 arg := [2]unsafe.Pointer{cstring(k), cstring(v)}
58 asmcgocall(_cgo_setenv, unsafe.Pointer(&arg))
59 }
60
61
62
63
64 func syscall_unsetenv_c(k string) {
65 if _cgo_unsetenv == nil {
66 return
67 }
68 arg := [1]unsafe.Pointer{cstring(k)}
69 asmcgocall(_cgo_unsetenv, unsafe.Pointer(&arg))
70 }
71
72 func cstring(s string) unsafe.Pointer {
73 p := make([]byte, len(s)+1)
74 copy(p, s)
75 return unsafe.Pointer(&p[0])
76 }
77
View as plain text