commit 2ec551087972ddb3535b0147de2c9c4b0620ee73 parent aef0a97bedd46608db499196f239c1a529801432 Author: Drew DeVault <sir@cmpwn.com> Date: Sat, 6 Mar 2021 16:40:46 -0500 os: add tryenv function Diffstat:
M | os/+linux/environ.ha | | | 7 | +++++++ |
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/os/+linux/environ.ha b/os/+linux/environ.ha @@ -48,6 +48,13 @@ export fn getenv(name: const str) (str | void) = { }; }; +// Looks up an environment variable and returns its value, or a default value if +// unset. +export fn tryenv(name: const str, default: str) str = match (getenv(name)) { + s: str => s, + void => default, +}; + let envp: []str = []; // Returns a slice of the environment strings in the form KEY=VALUE.