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
+13
View File
@@ -142,6 +142,15 @@ func Setenv(key, val string) (err error) {
return
}
func Unsetenv(key string) (err error) {
keydata := cstring(key)
errCode := libc_unsetenv(&keydata[0])
if errCode != 0 {
err = getErrno()
}
return
}
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
addr := libc_mmap(nil, uintptr(length), int32(prot), int32(flags), int32(fd), uintptr(offset))
if addr == unsafe.Pointer(^uintptr(0)) {
@@ -206,6 +215,10 @@ func libc_getenv(name *byte) *byte
//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
// ssize_t read(int fd, void *buf, size_t count);
//export read
func libc_read(fd int32, buf *byte, count uint) int
+5
View File
@@ -72,6 +72,11 @@ func Setenv(key, val string) (err error) {
return ENOSYS
}
func Unsetenv(key string) (err error) {
// stub for now
return ENOSYS
}
func Environ() []string {
env := runtime_envs()
envCopy := make([]string, len(env))