hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 1989e4a86d25e85aa548d84f68dbfa6c67315e84
parent 0495f2ed4d921ad2c7dfffab19295c88a72a7765
Author: Haelwenn (lanodan) Monnier <contact+sr.ht@hacktivis.me>
Date:   Sat, 30 Jul 2022 17:32:55 +0200

os::exec: Add unsetenv function

Diffstat:
Mos/exec/cmd.ha | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha @@ -90,11 +90,11 @@ export fn clearenv(cmd: *command) void = { cmd.env = []; }; -// Adds or sets a variable in the command environment. This does not affect the +// Removes a variable in the command environment. This does not affect the // current process environment. The 'key' must be a valid environment variable // name per POSIX definition 3.235. This includes underscores and alphanumeric // ASCII characters, and cannot begin with a number. -export fn setenv(cmd: *command, key: str, value: str) (void | errors::invalid) = { +export fn unsetenv(cmd: *command, key: str) (void | errors::invalid) = { let iter = strings::iter(key); for (let i = 0z; true; i += 1) match (strings::next(&iter)) { case void => @@ -120,7 +120,16 @@ export fn setenv(cmd: *command, key: str, value: str) (void | errors::invalid) = break; }; }; - append(cmd.env, strings::concat(fullkey, value)); +}; + + +// Adds or sets a variable in the command environment. This does not affect the +// current process environment. The 'key' must be a valid environment variable +// name per POSIX definition 3.235. This includes underscores and alphanumeric +// ASCII characters, and cannot begin with a number. +export fn setenv(cmd: *command, key: str, value: str) (void | errors::invalid) = { + unsetenv(cmd, key)?; + append(cmd.env, strings::join("=", key, value)); }; // Configures a file in the child process's file table, such that the file