diff options
author | Ayke van Laethem <[email protected]> | 2024-11-18 11:43:50 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2024-11-19 07:51:58 +0100 |
commit | 289fceb3eaf0829d1e3b65228b95a79bd5fc9389 (patch) | |
tree | a810ecbeb175b360173b1df87485e4d0f285163d /src/syscall/env_nonhosted.go | |
parent | e12da15f7d230874ca95a257c50bca0fc39f262c (diff) | |
download | tinygo-289fceb3eaf0829d1e3b65228b95a79bd5fc9389.tar.gz tinygo-289fceb3eaf0829d1e3b65228b95a79bd5fc9389.zip |
syscall: refactor environment handling
* Move environment functions to their own files.
* Rewrite the WASIp2 version of environment variables to be much
simpler (don't go through C functions).
Diffstat (limited to 'src/syscall/env_nonhosted.go')
-rw-r--r-- | src/syscall/env_nonhosted.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/syscall/env_nonhosted.go b/src/syscall/env_nonhosted.go new file mode 100644 index 000000000..446ba55d2 --- /dev/null +++ b/src/syscall/env_nonhosted.go @@ -0,0 +1,45 @@ +//go:build baremetal || js || wasm_unknown + +package syscall + +func Environ() []string { + env := runtime_envs() + envCopy := make([]string, len(env)) + copy(envCopy, env) + return envCopy +} + +func Getenv(key string) (value string, found bool) { + env := runtime_envs() + for _, keyval := range env { + // Split at '=' character. + var k, v string + for i := 0; i < len(keyval); i++ { + if keyval[i] == '=' { + k = keyval[:i] + v = keyval[i+1:] + } + } + if k == key { + return v, true + } + } + return "", false +} + +func Setenv(key, val string) (err error) { + // stub for now + return ENOSYS +} + +func Unsetenv(key string) (err error) { + // stub for now + return ENOSYS +} + +func Clearenv() (err error) { + // stub for now + return ENOSYS +} + +func runtime_envs() []string |