diff options
author | Ayke van Laethem <[email protected]> | 2023-01-14 23:10:44 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-01-17 08:38:54 +0100 |
commit | 3177591b3117f66beea08425c9e8339e253ff86c (patch) | |
tree | b9fbe9c71c990ad5ff8e5cb649b7c60bc9defd2d /src/syscall | |
parent | 19db0144aeacf12fabce9f02bd44dd60f0bfb694 (diff) | |
download | tinygo-3177591b3117f66beea08425c9e8339e253ff86c.tar.gz tinygo-3177591b3117f66beea08425c9e8339e253ff86c.zip |
syscall: implement setenv/unsetenv in the runtime
This is expected starting with Go 1.20.
I've also applied the same modification to syscall_libc.go so that
setenv is only called in a single place.
Diffstat (limited to 'src/syscall')
-rw-r--r-- | src/syscall/syscall_libc.go | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go index 002c9dc3f..5c7017101 100644 --- a/src/syscall/syscall_libc.go +++ b/src/syscall/syscall_libc.go @@ -197,21 +197,12 @@ func Setenv(key, val string) (err error) { return EINVAL } } - keydata := cstring(key) - valdata := cstring(val) - errCode := libc_setenv(&keydata[0], &valdata[0], 1) - if errCode != 0 { - err = getErrno() - } + runtimeSetenv(key, val) return } func Unsetenv(key string) (err error) { - keydata := cstring(key) - errCode := libc_unsetenv(&keydata[0]) - if errCode != 0 { - err = getErrno() - } + runtimeUnsetenv(key) return } @@ -312,6 +303,10 @@ func splitSlice(p []byte) (buf *byte, len uintptr) { return slice.buf, slice.len } +// These two functions are provided by the runtime. +func runtimeSetenv(key, value string) +func runtimeUnsetenv(key string) + //export strlen func libc_strlen(ptr unsafe.Pointer) uintptr @@ -325,16 +320,6 @@ func libc_write(fd int32, buf *byte, count uint) int //export getenv func libc_getenv(name *byte) *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 - // ssize_t read(int fd, void *buf, size_t count); // //export read |