linux-sysprog · beginner · ~15 min

Count open descriptors

Scan a descriptor table.

Challenge

An fd table uses -1 for a closed slot. Implement int count_open_fds(const int *table, int n) returning how many slots are open (!= -1).

Starter code

int count_open_fds(const int *table, int n) {
    /* TODO */
    return 0;
}

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