Skip to content

EnvGet

Description

Read an environment variable. Returns the value of environment variable name, or NULL if not set. Implementation calls into the platform env-lookup API so consumers don’t have to pull in libc headers for the prototype.

Parameters

Name Direction Description
name in NUL-terminated environment variable name.

Success

Returns a pointer to the value string (process-owned).

Failure

Returns NULL when name is NULL, when the variable is not set, or when the platform has no envp source linked (freestanding Windows, Darwin with no caller-captured envp).

Usage example (Cross-references)

Usage examples (Cross-references)
    #endif
    
    Zstr EnvGet(Zstr name) {
        if (!name) {
            return NULL;
        return NULL;
    #else
    #    error "EnvGet: unsupported platform (Linux x86_64/aarch64, Darwin, Windows only)"
    #endif
    }
    static Zstr tmp_dir_path(void) {
    #if PLATFORM_WINDOWS
        Zstr p = EnvGet("TEMP");
        if (p && *p)
            return p;
        if (p && *p)
            return p;
        p = EnvGet("TMP");
        if (p && *p)
            return p;
        return "C:/Windows/Temp";
    #else
        Zstr p = EnvGet("TMPDIR");
        if (p && *p)
            return p;
Last updated on