nftw different on BSD?

2019-07-28 04:48发布

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?

标签: c unix posix bsd nftw
1条回答
Rolldiameter
2楼-- · 2019-07-28 05:31

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.

查看更多
登录 后发表回答