linux-sysprog · intermediate · ~15 min
`getenv` and the convention "missing or empty means absent".
Implement const char *getenv_default(const char *name, const char *fallback) returning the value of the environment variable name if set and non-empty, otherwise fallback.
#include <stdlib.h>
const char *getenv_default(const char *name, const char *fallback) {
/* TODO */
return fallback;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.