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) char *name; struct stat statb;

     DESCRIPTION
          Ftw recursively descends the directory hierarchy rooted in
          path. For each object in the hierarchy, ftw calls fn, pass-
          ing it a pointer to a null-terminated character string con-
          taining the name of the object, a pointer to a stat struc-
          ture (see stat(2)) containing information about the object,
          and an integer.  Possible values of the integer, defined in
          <ftw.h>, are FTW_F for a file, FTW_D for a directory,
          FTW_DNR for a directory that cannot be read, and FTW_NS for
          an object on which stat failed.  If the integer is FTW_DNR,
          descendents of that directory will not be processed.  If the
          integer is FTW_NS, the stat structure will contain garbage.

          Ftw visits a directory before visiting any of its descen-
          dents.

          The tree traversal continues until the tree is exhausted, an
          invocation of fn returns a nonzero value, or some error is
          detected within ftw (such as an I/O error).  If the tree is
          exhausted, ftw returns zero.  If fn returns a nonzero value,
          ftw stops its tree traversal and returns whatever value was
          returned by fn. If ftw detects an error, it returns -1, and
          indicates the error type in errno.

          Ftw uses one file descriptor for each level in the tree.
          The depth argument limits the number of file descriptors so
          used.  If depth is zero or negative, the effect is the same
          as if it were 1.  Depth must not be greater than the number
          of file descriptors currently available for use.  Ftw will
          run more quickly if depth is at least as large as the number
          of levels in the tree.

     BUGS
          Ftw doesn't recognize symbolic links, which can cause

     FTW(3)                                                     FTW(3)

          infinite recursion.