[illumos-Developer] nftw(3c) question
Jason King
jason.brian.king at gmail.com
Thu Jan 13 14:41:24 PST 2011
Having a need to use nftw(3c), I also needed a way to have it not
descend certain directories. Looking at the source, it appears if you
set the quit field of the FTW struct passed into the callback to
FTW_PRUNE, this accomplishes this. For example:
#include <ftw.c>
boolean_t
ignore_subtree(const char *path)
{
if (....some test on pathname)
return (B_TRUE);
return (B_FALSE);
}
int
walker(const char *path, const struct stat *sp, int flag, struct FTW *state)
{
if (ignore_subtree(path)) {
state->quit = FTW_PRUNE;
return (0);
}
.....
other processing on path
.....
return (0);
}
int
main(int argc, char **argv)
{
int rc = nftw(path, walk, 5, FTW_PHYS);
....
}
This works, but it's completely undocumented. However, looking at the
source, it strongly suggests that the 'quit' field was intended to be
used in that manner (and is not merely some internal state being used
by the implementation). Which if correct, just points to a
documentation issue. Can anyone perhaps offer any historical insight?
More information about the Developer
mailing list