linux-sysprog · beginner · ~15 min

Boolean environment flag

Interpret an env var as a boolean.

Challenge

Implement int env_is_true(const char *name) returning 1 if the variable is set to exactly "1" or "true", else 0.

Starter code

#include <stdlib.h>
#include <string.h>

int env_is_true(const char *name) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.