//> cflags: -Ofast import "std/env.zc" fn main() -> int { // ---- // get: Retrieves the env-let as borrowed string (char *) (no alloc) // --- // @Example usage: On Linux (and some variants) PATH is already defined. // --- let path = Env::get("PATH"); if (path.is_some()) { println "PATH is: {path.unwrap()}"; } else { println "PATH is not set"; } // ---- // set: Sets an env-let variable // get_dup: Retrieves the env-let as caller-owned String() (heap alloc) // --- // @Example usage: In your terminal type "export HELLO=world" or use Env::set() // --- let res = Env::set("HELLO", "world"); //=> check res against EnvRes::OK() let hello = Env::get_dup("HELLO"); if (hello.is_some()) { let hello_str = hello.unwrap(); defer hello_str.free(); println "HELLO is: {hello_str.c_str()}"; } else { println "HELLO is not set"; } // ---- // unset: Unsets an existing env-let // --- Env::unset("HELLO"); let hello_now2 = Env::get("HELLO"); if (hello_now2.is_none()) { println "HELLO is now unset"; } }