问题
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?
回答1:
What is the return value of nftw
? If it's -1
and the errno is
set to EINVAL
it's quite likely that you're exceeding the value of OPEN_MAX
. Try passing a smaller value as third parameter to nftw
and ensure it's smaller than OPEN_MAX
.
来源:https://stackoverflow.com/questions/8093315/nftw-different-on-bsd