FTW(3) FTW(3) NAME ftw - file tree walk SYNOPSIS #include <ftw.h> int ftw(path, fn, depth) char *path; int (*fn)(); int depth; #include <sys/types.h> #include <sys/stat.h> fn(name, statb, code, S) char *name; struct stat *statb; struct FTW *S; DESCRIPTION Ftw recursively descends the directory hierarchy rooted in path. For each entry in the hierarchy, ftw calls fn, passing it information about the entry: a pointer to a null- terminated pathname string, a pointer to a stat structure (see stat(2)), and a pointer to the following structure. struct FTW { int quit; see below int base; &name[base] points to basename int level; recursion level (initially 0) }; Possible values of code, defined in are FTW_D Entry is a directory (before visiting descendants). FTW_DP Entry is a directory (after visiting descendants). FTW_SL Entry is a symbolic link. FTW_F Entry is some other kind of file. FTW_DNR Entry is a directory that cannot be read; no descendants will be visited. FTW_NS Lstat (see stat(2)) failed on name; contents of statb are undefined FTW_NSL Lstat succeeded, but stat failed; contents of statb are undefined. The tree traversal continues until the tree is exhausted or fn returns a nonzero value. When the tree is exhausted, ftw returns zero. When fn returns a nonzero value, ftw stops and returns that value. FTW(3) FTW(3) Normally symbolic links are not followed. But if on a sym- bolic link (FTW_SL) fn sets S->quit to FTW_FOLLOW, ftw will next attempt to follow the link. Ftw normally visits a readable directory twice, before and after visiting its descendants. But if on a previsit (FTW_D) fn sets S->quit to FTW_SKD, ftw will skip the descendants and the postvisit (FTW_DP). Ftw uses one file descriptor for each level in the tree up to a maximum of depth (or 1, if depth<1) descriptors. Depth must not exceed the number of available file descriptors; small values of depth may cause ftw to run slowly, but will not change its effect. SEE ALSO stat(2), directory(3) DIAGNOSTICS Ftw returns -1 with errno set to ENOMEM when malloc(3) fails. Errno is set appropriately when ftw calls fn with code FTW_DNR, FTW_NS, or FTW_NSL.