No matching definitions.

tur/env

stdlib/env.tur

environment variable access (getenv, setenv, unsetenv).

Since: Phase B1

defn

env/get-raw

(env/get-raw [name : cstr])

look up an environment variable by name.

namethe variable name as a NUL-terminated cstr (e.g., "HOME")

A some option whose int64_t value is the cstr pointer, or none if the variable is not set. The returned pointer is owned by the OS environment; do not free it.

(env/get "HOME")  ; => some(<cstr ptr>)

Since: Phase B2

defn

env/get

(env/get [name : cstr])

by-value: some(value cstr) if set, none otherwise.

defn

env/get!

(env/get! [name : cstr])

look up an environment variable, panicking if missing.

namethe variable name as a NUL-terminated cstr

The value cstr. Panics if the variable is not set.

(env/get! "HOME")  ; => "/home/user"  ; doctest: value depends on the environment

Since: Phase B2

defn

env/set

(env/set [name : cstr value : cstr])

set an environment variable.

namevariable name cstr
valuenew value cstr

0 on success, -1 on error.

(env/set "MY_VAR" "hello")  ; => 0

Since: Phase B2

defn

env/unset

(env/unset [name : cstr])

unset an environment variable.

namevariable name cstr

0 on success, -1 on error.

(env/unset "MY_VAR")  ; => 0

Since: Phase B2

defn

env/all

(env/all)

return all environment variables as a cons list of "KEY=VALUE" cstrs.

A freshly allocated cons list where each element is a strdup'd "KEY=VALUE" cstr from the OS environment. Free with env/all-free.

(env/all)  ; => cons("PATH=...", cons("HOME=...", 0))

Since: Phase B2

defn

env/all-free

(env/all-free [lst : int] :)

free a cons list returned by env/all.

lstcons list returned by env/all
(env/all-free my-env-list)

Since: Phase B2

defn

env/home

(env/home)

return the HOME environment variable, if set.

some(value) holding the home directory as a cstr owned by the OS environment (do not free it), or none when HOME is unset.

(env/home)  ; => some("/home/user")  ; doctest: value depends on the environment

Since: Phase B2

defn

env/path

(env/path)

return the PATH environment variable, if set.

some(value) holding the executable search path as a cstr owned by the OS environment (do not free it), or none when PATH is unset.

(env/path)  ; => some("/usr/bin:/bin:/usr/local/bin")  ; doctest: value depends on the environment

Since: Phase B2

defn

env/user

(env/user)

return the USER environment variable, if set.

some(value) holding the login name as a cstr owned by the OS environment (do not free it), or none when USER is unset.

(env/user)  ; => some("alice")  ; doctest: value depends on the environment

Since: Phase B2

defn

env/shell

(env/shell)

return the SHELL environment variable, if set.

some(value) holding the login shell as a cstr owned by the OS environment (do not free it), or none when SHELL is unset.

(env/shell)  ; => some("/bin/bash")  ; doctest: value depends on the environment

Since: Phase B2