cybersecurity · beginner · ~15 min

Check a return code

Normalise a syscall return into success/failure.

Challenge

Implement int handle_rc(int rc) returning 0 if rc >= 0 (success) and -1 otherwise — the discipline of checking every call before proceeding.

Starter code

int handle_rc(int rc) {
    /* TODO */
    return -1;
}

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