diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2014-10-01 11:17:15 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2014-10-01 11:17:15 -0700 |
commit | 85cdc49e8abed5c48d9b24eedff85e44e38269b9 (patch) | |
tree | 7b3433248b7b481c281ddba1bbf70c3b6851c4d6 /src/runtime/env_posix.go | |
parent | 1a1341afed8454c40d86b20aa3950b75c60068ea (diff) | |
download | go-85cdc49e8abed5c48d9b24eedff85e44e38269b9.tar.gz go-85cdc49e8abed5c48d9b24eedff85e44e38269b9.zip |
os, syscall: add Unsetenv
Also address a TODO, making Clearenv pass through to cgo.
Based largely on Minux's earlier https://golang.org/cl/82040044
Fixes #6423
LGTM=iant, alex.brainman, r, rsc
R=rsc, iant, r, alex.brainman
CC=golang-codereviews
https://golang.org/cl/148370043
Diffstat (limited to 'src/runtime/env_posix.go')
-rw-r--r-- | src/runtime/env_posix.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/runtime/env_posix.go b/src/runtime/env_posix.go index 6c04f6cc70..dd57872d7c 100644 --- a/src/runtime/env_posix.go +++ b/src/runtime/env_posix.go @@ -32,7 +32,8 @@ func gogetenv(key string) string { return "" } -var _cgo_setenv uintptr // pointer to C function +var _cgo_setenv uintptr // pointer to C function +var _cgo_unsetenv uintptr // pointer to C function // Update the C environment if cgo is loaded. // Called from syscall.Setenv. @@ -44,6 +45,16 @@ func syscall_setenv_c(k string, v string) { asmcgocall(unsafe.Pointer(_cgo_setenv), unsafe.Pointer(&arg)) } +// Update the C environment if cgo is loaded. +// Called from syscall.unsetenv. +func syscall_unsetenv_c(k string) { + if _cgo_unsetenv == 0 { + return + } + arg := [1]unsafe.Pointer{cstring(k)} + asmcgocall(unsafe.Pointer(_cgo_unsetenv), unsafe.Pointer(&arg)) +} + func cstring(s string) unsafe.Pointer { p := make([]byte, len(s)+1) sp := (*_string)(unsafe.Pointer(&s)) |