OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows | 5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows |
6 | 6 |
7 package runtime | 7 package runtime |
8 | 8 |
9 import "unsafe" | 9 import "unsafe" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 gothrow("getenv before env init") | 25 gothrow("getenv before env init") |
26 } | 26 } |
27 for _, s := range environ() { | 27 for _, s := range environ() { |
28 if len(s) > len(key) && s[len(key)] == '=' && s[:len(key)] == ke
y { | 28 if len(s) > len(key) && s[len(key)] == '=' && s[:len(key)] == ke
y { |
29 return s[len(key)+1:] | 29 return s[len(key)+1:] |
30 } | 30 } |
31 } | 31 } |
32 return "" | 32 return "" |
33 } | 33 } |
34 | 34 |
35 var _cgo_setenv uintptr // pointer to C function | 35 var _cgo_setenv uintptr // pointer to C function |
| 36 var _cgo_unsetenv uintptr // pointer to C function |
36 | 37 |
37 // Update the C environment if cgo is loaded. | 38 // Update the C environment if cgo is loaded. |
38 // Called from syscall.Setenv. | 39 // Called from syscall.Setenv. |
39 func syscall_setenv_c(k string, v string) { | 40 func syscall_setenv_c(k string, v string) { |
40 if _cgo_setenv == 0 { | 41 if _cgo_setenv == 0 { |
41 return | 42 return |
42 } | 43 } |
43 arg := [2]unsafe.Pointer{cstring(k), cstring(v)} | 44 arg := [2]unsafe.Pointer{cstring(k), cstring(v)} |
44 asmcgocall(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg)) | 45 asmcgocall(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg)) |
45 } | 46 } |
46 | 47 |
| 48 // Update the C environment if cgo is loaded. |
| 49 // Called from syscall.unsetenv. |
| 50 func syscall_unsetenv_c(k string) { |
| 51 if _cgo_unsetenv == 0 { |
| 52 return |
| 53 } |
| 54 arg := [1]unsafe.Pointer{cstring(k)} |
| 55 asmcgocall(unsafe.Pointer(_cgo_unsetenv), unsafe.Pointer(&arg)) |
| 56 } |
| 57 |
47 func cstring(s string) unsafe.Pointer { | 58 func cstring(s string) unsafe.Pointer { |
48 p := make([]byte, len(s)+1) | 59 p := make([]byte, len(s)+1) |
49 sp := (*_string)(unsafe.Pointer(&s)) | 60 sp := (*_string)(unsafe.Pointer(&s)) |
50 memmove(unsafe.Pointer(&p[0]), unsafe.Pointer(sp.str), uintptr(len(s))) | 61 memmove(unsafe.Pointer(&p[0]), unsafe.Pointer(sp.str), uintptr(len(s))) |
51 return unsafe.Pointer(&p[0]) | 62 return unsafe.Pointer(&p[0]) |
52 } | 63 } |
OLD | NEW |