file-handling · intermediate · ~15 min

Is it a regular file?

Inspect the file-type bits of st_mode.

Challenge

Implement int is_regular_file(const char *path) returning 1 if path is a regular file (use stat + S_ISREG), else 0 (including when stat fails).

Starter code

#include <sys/stat.h>

int is_regular_file(const char *path) {
    /* TODO */
    return 0;
}

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