cybersecurity · beginner · ~15 min

Safe write length

Cap a write at the buffer size.

Challenge

Implement int safe_write_len(int want, int buf_size) returning how many bytes you can safely write (min of the two, never negative).

Starter code

int safe_write_len(int want, int buf_size) {
    /* TODO */
    return 0;
}

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