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