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

 NAME

nftw - walk a file tree

 SYNOPSIS



#include <ftw.h>

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

 DESCRIPTION

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:
FTW_CHDIR
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.
FTW_DEPTH
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.
FTW_MOUNT
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.
FTW_PHYS
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.

 RETURN VALUE

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

 ERRORS

The nftw() function will fail if:
[EACCES]
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.
[ENAMETOOLONG]
The length of the path string exceeds {PATH_MAX}, or a pathname component is longer than {NAME_MAX}.
[ENOENT]
A component of path does not name an existing file or path is an empty string.
[ENOTDIR]
A component of path is not a directory.

The nftw() function may fail if:

[ELOOP]
Too many symbolic links were encountered in resolving path.
[EMFILE]
{OPEN_MAX} file descriptors are currently open in the calling process.
[ENAMETOOLONG]
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
[ENFILE]
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.

 EXAMPLES

None.

 APPLICATION USAGE

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

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 ]