cybersecurity · beginner · ~15 min

Check a return code

Normalise a syscall return into success/failure.

Challenge

Normalise a raw syscall return into a clean success/failure signal — the discipline of checking every call before proceeding.

Task

Implement int handle_rc(int rc) that returns 0 for success and -1 for failure.

Input

  • rc: a return code (a syscall-style result) the grader passes.

Output

Returns int: 0 if rc >= 0 (success), -1 otherwise.

Example

handle_rc(5)    ->   0
handle_rc(0)    ->   0
handle_rc(-1)   ->   -1

Edge cases

  • rc == 0 counts as success.

Input format

An int rc (a syscall-style return code).

Output format

An int: 0 if rc >= 0, else -1.

Constraints

rc == 0 is success.

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.