int ftw(const char *directory, int (*funcptr )(const char *file, struct stat *sb, int flag), int depth);
FTW_F Item is a normal file FTW_D Item is a directory FTW_NS The stat failed on the item FTW_DNR Item is a directory which can't be read
ftw() recursively calls itself for traversing found directories. To avoid using up all a program's file descriptors, the depth specifies the number of simultaneous open directories. When the depth is exceeded, ftw() will become slower because directories have to be closed and reopened.
To stop the tree walk, funcptr returns a non-zero value; this value will become the return value of ftp(). Otherwise, ftw() will continue until it has traversed the entire tree, in which case it will return zero, or until it hits an error such as a malloc(3) failure, in which case it will return -1.
Because ftp() uses dynamic data structures, the only safe way to exit out of a tree walk is to return a non-zero value. To handle interrupts, for example, mark that the interrupt occurred and return a non-zero value---don't use longjmp(3) unless the program is going to terminate.