linux-sysprog · beginner · ~15 min
Distinguish absolute from relative paths.
execv does not search $PATH, so it needs an absolute path — one that begins at the filesystem root with '/'.
Implement int is_absolute_path(const char *p) that returns 1 if p is non-empty and its first character is '/', else 0.
p: a path string (possibly empty).1 if p[0] == '/' (and p is non-empty), else 0.
is_absolute_path("/bin/ls") -> 1
is_absolute_path("ls") -> 0
is_absolute_path("./a") -> 0
is_absolute_path("") -> 0
ls, ./a): return 0.p: a path string, possibly empty.
1 if non-empty and starts with '/', else 0.
int is_absolute_path(const char *p) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.