Linux System Programming · intermediate · ~8 min
Read and modify the process environment.
Each process has a list of NAME=value strings (the environment). char *getenv(const char *name) returns the value (or NULL). setenv / unsetenv mutate it; clearenv wipes it.
Children inherit a copy of the parent's environment. Useful for configuration that varies by deployment without changing code.
const char *home = getenv("HOME");
if (home) printf("%s\n", home);