networking · beginner · ~15 min

Valid socket fd?

Check the socket() result.

Challenge

socket() returns a non-negative fd on success or -1 on error. Implement int socket_ok(int fd) returning 1 if fd >= 0, else 0.

Starter code

int socket_ok(int fd) {
    /* TODO */
    return 0;
}

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