The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


nftw - walk a file tree


#include <ftw.h>

int nftw(const char *path, int (*fn)(const char *,
    const struct stat *, int, struct FTW *), int depth, int flags);


The nftw() function recursively descends the directory hierarchy rooted in path. The nftw() function has a similar effect to ftw() except that it takes an additional argument flags, which is a bitwise inclusive-OR of zero or more of the following flags:
If set, nftw() will change the current working directory to each directory as it reports files in that directory. If clear, nftw() will not change the current working directory.
If set, nftw() will report all files in a directory before reporting the directory itself. If clear, nftw() will report any directory before reporting the files in that directory.
If set, nftw() will only report files in the same file system as path. If clear, nftw() will report all files encountered during the walk.
If set, nftw() performs a physical walk and does not follow symbolic links. If clear, nftw() will follow links instead of reporting them, and will not report the same file twice.

At each file it encounters, nftw() calls the user-supplied function fn() with four arguments:

The argument depth sets the maximum number of file descriptors that will be used by nftw() while traversing the file tree. At most one file descriptor will be used for each directory level.


The nftw() function continues until the first of the following conditions occurs:


The nftw() function will fail if:
Search permission is denied for any component of path or read permission is denied for path, or fn() returns -1 and does not reset errno.
The length of the path string exceeds {PATH_MAX}, or a pathname component is longer than {NAME_MAX}.
A component of path does not name an existing file or path is an empty string.
A component of path is not a directory.

The nftw() function may fail if:

Too many symbolic links were encountered in resolving path.
{OPEN_MAX} file descriptors are currently open in the calling process.
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
Too many files are currently open in the system.

In addition, errno may be set if the function pointed by fn() causes errno to be set.








lstat(), opendir(), readdir(), stat(), <ftw.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]