I'm trying to get all .c files in a directory tree using nftw
with the following code:
static int gf(const char *path, const struct stat *st, int t, struct FTW *ftw) {
if (t != FTW_F)
return 0;
if (strcmp(ext(path), ".c") == 0)
addl(&files, dup(abspath(path)));
return 0;
}
void getfiles(char *path) {
nftw(path, gf, 255, FTW_PHYS);
}
It works on Linux and Solaris, but on PC-BSD it fails by simply not picking up any files. What am I missing?
What is the return value of
nftw
? If it's-1
and theerrno is
set toEINVAL
it's quite likely that you're exceeding the value ofOPEN_MAX
. Try passing a smaller value as third parameter tonftw
and ensure it's smaller thanOPEN_MAX
.