No matching definitions.

tur/env

stdlib/env.tur

environment variable access (getenv, setenv, unsetenv).

Since: Phase B1

defn

env/get

(env/get [name :cstr] :int)

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] :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"

Since: Phase B2

defn

env/set

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

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] :int)

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 :int)

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] :void)

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 :cstr)

return the HOME environment variable.

The HOME cstr, or NULL if not set.

(env/home)  ; => "/home/user"

Since: Phase B2

defn

env/path

(env/path :cstr)

return the PATH environment variable.

The PATH cstr, or NULL if not set.

(env/path)  ; => "/usr/bin:/bin:/usr/local/bin"

Since: Phase B2

defn

env/user

(env/user :cstr)

return the USER environment variable.

The USER cstr, or NULL if not set.

(env/user)  ; => "alice"

Since: Phase B2

defn

env/shell

(env/shell :cstr)

return the SHELL environment variable.

The SHELL cstr, or NULL if not set.

(env/shell)  ; => "/bin/bash"

Since: Phase B2