networking · beginner · ~15 min

Did bind succeed?

Interpret bind()'s 0/-1 return.

Challenge

Interpret the return code of bind(), which follows the usual POSIX 0/-1 convention.

Task

Implement int bind_succeeded(int rc).

Input

  • rc: the value bind() returned.

Output

Return 1 if rc == 0 (success), else 0.

Example

bind_succeeded(0)   ->  1
bind_succeeded(-1)  ->  0

Input format

rc: the return value of bind().

Output format

1 if rc == 0, else 0.

Constraints

bind() returns 0 on success, -1 on error.

Starter code

int bind_succeeded(int rc) {
    /* TODO */
    return 0;
}

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