mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
19db0144ae
commit
3177591b31
@@ -1,28 +1,40 @@
|
||||
//go:build linux
|
||||
//go:build linux || darwin
|
||||
|
||||
package runtime
|
||||
|
||||
// Update the C environment if cgo is loaded.
|
||||
// Called from syscall.Setenv.
|
||||
// Called from Go 1.20 and above.
|
||||
//
|
||||
//go:linkname syscall_setenv_c syscall.setenv_c
|
||||
func syscall_setenv_c(key string, val string) {
|
||||
//go:linkname syscallSetenv syscall.runtimeSetenv
|
||||
func syscallSetenv(key, value string) {
|
||||
keydata := cstring(key)
|
||||
valdata := cstring(val)
|
||||
valdata := cstring(value)
|
||||
// ignore any errors
|
||||
libc_setenv(&keydata[0], &valdata[0], 1)
|
||||
return
|
||||
}
|
||||
|
||||
// Update the C environment if cgo is loaded.
|
||||
// Called from syscall.Unsetenv.
|
||||
// Called from Go 1.20 and above.
|
||||
//
|
||||
//go:linkname syscall_unsetenv_c syscall.unsetenv_c
|
||||
func syscall_unsetenv_c(key string) {
|
||||
//go:linkname syscallUnsetenv syscall.runtimeUnsetenv
|
||||
func syscallUnsetenv(key string) {
|
||||
keydata := cstring(key)
|
||||
// ignore any errors
|
||||
libc_unsetenv(&keydata[0])
|
||||
return
|
||||
}
|
||||
|
||||
// Compatibility with Go 1.19 and below.
|
||||
//
|
||||
//go:linkname syscall_setenv_c syscall.setenv_c
|
||||
func syscall_setenv_c(key string, val string) {
|
||||
syscallSetenv(key, val)
|
||||
}
|
||||
|
||||
// Compatibility with Go 1.19 and below.
|
||||
//
|
||||
//go:linkname syscall_unsetenv_c syscall.unsetenv_c
|
||||
func syscall_unsetenv_c(key string) {
|
||||
syscallUnsetenv(key)
|
||||
}
|
||||
|
||||
// cstring converts a Go string to a C string.
|
||||
Reference in New Issue
Block a user