networking · beginner · ~15 min

Did socket() fail?

Detect the socket() error sentinel.

Challenge

Implement int socket_failed(int fd) returning 1 if fd < 0, else 0.

Starter code

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

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