blob: cfe8c7f858bb56c0b6788c5a0061857d939dc400 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//go:build linux
// +build linux
package runtime
// Update the C environment if cgo is loaded.
// Called from syscall.Setenv.
//
//go:linkname syscall_setenv_c syscall.setenv_c
func syscall_setenv_c(key string, val string) {
keydata := cstring(key)
valdata := cstring(val)
// ignore any errors
libc_setenv(&keydata[0], &valdata[0], 1)
return
}
// Update the C environment if cgo is loaded.
// Called from syscall.Unsetenv.
//
//go:linkname syscall_unsetenv_c syscall.unsetenv_c
func syscall_unsetenv_c(key string) {
keydata := cstring(key)
// ignore any errors
libc_unsetenv(&keydata[0])
return
}
// cstring converts a Go string to a C string.
// borrowed from syscall
func cstring(s string) []byte {
data := make([]byte, len(s)+1)
copy(data, s)
// final byte should be zero from the initial allocation
return data
}
// int setenv(const char *name, const char *val, int replace);
//
//export setenv
func libc_setenv(name *byte, val *byte, replace int32) int32
// int unsetenv(const char *name);
//
//export unsetenv
func libc_unsetenv(name *byte) int32
|