Skip to content

EnvGet

Description

Read an environment variable. Direct wrapper over the OS-supplied getenv (libc on POSIX, GetEnvironmentVariableA on Windows) so that consumers don’t have to pull <stdlib.h> 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 the variable is not set.

Usage example (Cross-references)

Usage examples (Cross-references)
    static const char *tmp_dir_path(void) {
    #ifdef _WIN32
        const char *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
        const char *p = EnvGet("TMPDIR");
        if (p && *p)
            return p;
    #endif
    
    const char *EnvGet(const char *name) {
        if (!name) {
            return NULL;
Last updated on