linux-sysprog · intermediate · ~15 min
Follow the errno-setting convention in your APIs.
Implement int checked_div(int a, int b, int *out) that, on b == 0, sets errno = EDOM and returns -1; otherwise stores a/b in *out and returns 0.
#include <errno.h>
int checked_div(int a, int b, int *out) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.