Basically, so far I have this code:
# define ERROR 1
# define FAILURE -1
int main(int ac, char **av)
i = 0;
if (ac == 1)
if (glob(av, GLOB_PERIOD, NULL, &globlist) == GLOB_NOSPACE
|| glob(av, GLOB_PERIOD, NULL, &globlist) == GLOB_NOMATCH)
if (glob(av, GLOB_PERIOD, NULL, &globlist) == GLOB_ABORTED)
(It is absolutely silly to reinvent the wheel by going at it using opendir()/readdir()/closedir(), especially because nftw() should handle filesystem changes gracefully, whereas self-spun tree walking code usually ignores all the hard stuff, and only works in optimal conditions on your own machine, failing in spectacular and wonderful ways elsewhere.)
In the filter function, use
fnmatch() to decide whether the file name is acceptable using glob patterns.
If you wish to filter using regular expressions instead, use
regcomp() to compile the pattern(s) before calling nftw(), then
regexec() in your filter function. (Regular expressions are more powerful than glob patterns, and they are compiled to a tight state machine, so they are quite efficient, too.)
All of the above are defined in POSIX.1-2008, so they are portable across all POSIX-y operating systems.