Env
Source: std/env.mw.
Command-line arguments and environment variables. Call env_init from main first:
@export fn main(argc: i32, argv: rawptr) -> i32 { env_init(argc, argv); ... arg_get(1) ... env_get("HOME") ...The environment block is read from the stack layout every System V style entry point provides (envp follows argv), so this works on Linux and macOS without libc. Windows keeps its environment elsewhere: there env_get returns null.
Constants
Section titled “Constants”| Name | Type | Value | Notes |
|---|---|---|---|
ENV_ARGC |
i64 |
0 |
|
ENV_ARGV |
i64 |
0 |
|
ENV_OK |
i64 |
0 |
Functions
Section titled “Functions”env_init
Section titled “env_init”fn env_init(argc: i32, argv: rawptr)arg_count
Section titled “arg_count”fn arg_count() -> i64arg_get
Section titled “arg_get”fn arg_get(i: i64) -> *u8The i-th argument (0 is the program name), or null when out of range.
env_block
Section titled “env_block”fn env_block() -> *i64env_count
Section titled “env_count”fn env_count() -> i64Number of “NAME=value” entries.
env_at
Section titled “env_at”fn env_at(i: i64) -> *u8The i-th “NAME=value” entry, or null.
env_get
Section titled “env_get”fn env_get(name: *u8) -> *u8Value of the variable (a pointer into the environment block), or null.
env_get_or
Section titled “env_get_or”fn env_get_or(name: *u8, fallback: *u8) -> *u8Like env_get but returns fallback when the variable is not set.