nftw

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

How avoid using global variable when using nftw

落爺英雄遲暮 提交于 2019-11-28 11:13:02
I want to use nftw to traverse a directory structure in C. However, given what I want to do, I don't see a way around using a global variable. The textbook examples of using (n)ftw all involve doing something like printing out a filename. I want, instead, to take the pathname and file checksum and place those in a data structure. But I don't see a good way to do that, given the limits on what can be passed to nftw. The solution I'm using involves a global variable. The function called by nftw can then access that variable and add the required data. Is there any reasonable way to do this

How avoid using global variable when using nftw

喜你入骨 提交于 2019-11-27 06:10:42
问题 I want to use nftw to traverse a directory structure in C. However, given what I want to do, I don't see a way around using a global variable. The textbook examples of using (n)ftw all involve doing something like printing out a filename. I want, instead, to take the pathname and file checksum and place those in a data structure. But I don't see a good way to do that, given the limits on what can be passed to nftw. The solution I'm using involves a global variable. The function called by nftw