简体   繁体   English

nftw在BSD上有所不同?

[英]nftw different on BSD?

I'm trying to get all .c files in a directory tree using nftw with the following code: 我正在尝试使用nftw通过以下代码获取目录树中的所有.c文件:

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. 它可以在Linux和Solaris上运行,但是在PC-BSD上,由于不选择任何文件而失败。 What am I missing? 我想念什么?

What is the return value of nftw ? nftw的返回值是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 . 如果它为-1errno is设置为EINVAL则很可能超出了OPEN_MAX的值。 Try passing a smaller value as third parameter to nftw and ensure it's smaller than OPEN_MAX . 尝试将较小的值作为第三个参数传递给nftw并确保它小于OPEN_MAX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM