nftw different on BSD?

送分小仙女□ 提交于 2019-12-11 07:56:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!