os: implement and smoketest os.Unsetenv

This commit is contained in:
Dan Kegel
2021-12-11 09:55:21 -08:00
committed by Ron Evans
parent cff4493ca0
commit e4f2b9c003
5 changed files with 64 additions and 2 deletions
+14
View File
@@ -13,6 +13,16 @@ func syscall_setenv_c(key string, val string) {
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 {
@@ -25,3 +35,7 @@ func cstring(s string) []byte {
// 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