linux-sysprog · intermediate · ~15 min

errno after a failed open

Read errno after a failed syscall.

Challenge

Implement int missing_file_errno(void) that tries to open a file that does not exist (O_RDONLY) and returns the resulting errno value.

Starter code

#include <fcntl.h>
#include <errno.h>

int missing_file_errno(void) {
    /* TODO */
    return 0;
}

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