logos.std.env

Module std · package logos-std

Functions

fnarg

fn arg(i: i32) -> &[u8]

Returns command-line argument i as a str, or "" if i is out of range.

fnargs_count

fn args_count() -> i32

Returns the number of command-line arguments, including argv[0].

Returns 0 if /proc/self/cmdline could not be read at startup (e.g. in a sandbox).

fncurrent_dir

fn current_dir() -> Option

Returns the current working directory as an owned String, or None on error.

fncurrent_exe

fn current_exe() -> Option

Returns the path of the running executable, or None if it cannot be determined.

Resolved through /proc/self/exe, following the symlink chain to the real file.

fnget_option

fn get_option(long_name: &[u8], short_name: &[u8]) -> Option

Looks up an option value: --long=VALUE, --long VALUE, or -s VALUE (short form only when short_name.len() == 1). Returns Option::None if not found, or if scanning reaches the -- terminator first.

fnhas_flag

fn has_flag(long_name: &[u8], short_name: &[u8]) -> bool

Returns true if --long_name or -short_name appears as a bare flag in argv. Stops scanning at the -- terminator; short_name may be "" to disable short-flag matching.

fnpositional

fn positional(idx: i32) -> &[u8]

Returns the idx-th positional argument (0-indexed), or "" if out of range.

fnpositional_count

fn positional_count() -> i32

Returns the count of positional arguments (non-flags; everything after -- counts too).

fnprogram_name

fn program_name() -> &[u8]

Returns the program name (argv[0]); useful for usage messages.

fnset_current_dir

fn set_current_dir(path: &[u8]) -> i32

Changes the process working directory to path.

Returns the raw libc chdir result: 0 on success, -1 on failure.

fnvar

fn var(name: *const u8) -> Option

Returns the value of the environment variable named by NUL-terminated C string name, or None if unset.

The returned str borrows libc environ storage; a later setenv may invalidate it.

fnvar_is_set

fn var_is_set(name: *const u8) -> bool

Returns true if the environment variable named by NUL-terminated C string name is set.