Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
nftw(3)
Edit
PageHistory
Diff
Info
LikePages
FTW !!!FTW NAME SYNOPSIS DESCRIPTION NOTES CONFORMING TO SEE ALSO ---- !!NAME ftw, nftw - file tree walk !!SYNOPSIS __#include __ __int ftw (const char *__''dir''__, int (*__''fn''__)(const char *__''file''__, const struct stat *__''sb''__, int__ ''flag''__), int__ ''depth''__);__ __int nftw (const char *__''dir''__, int (*__''fn''__)(const char *__''file''__, const struct stat *__''sb''__, int__ ''flag''__, struct FTW *__''s''__), int__ ''depth''__, int__ ''flags''__);__ !!DESCRIPTION __ftw__() walks through the directory tree starting from the indicated directory ''dir''. For each found entry in the tree, it calls ''fn''() with the full pathname of the entry, a pointer to the stat(2) structure for the entry and an int ''flag'', which value will be one of the following: __FTW_F__ Item is a normal file __FTW_D__ Item is a directory __FTW_DNR__ Item is a directory which can't be read __FTW_SL__ Item is a symbolic link __FTW_NS__ The stat failed on the item which is not a symbolic link If the item is a symbolic link and stat failed, XPG4v2 states that it is undefined whether FTW_NS or FTW_SL is used. __ftw__() recursively calls itself for traversing found directories, handling a directory before its files or subdirectories. 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. __ftw__() uses at most one file descriptor for each level in the file hierarchy. To stop the tree walk, ''fn''() returns a non-zero value; this value will become the return value of __ftw__(). Otherwise, __ftw__() will continue until it has traversed the entire tree, in which case it will return zero, or until it hits an error other than EACCES (such as a malloc(3) failure), in which case it will return -1. Because __ftw()__ 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. The function __nftw__() does precisely the same as __ftw__(), except that it has one additional argument ''flags'' (and calls the supplied function with one more argument). This ''flags'' argument is an OR of zero or more of the following flags: __FTW_CHDIR__ If set, do a ''chdir''() to each directory before handling its contents. __FTW_DEPTH__ If set, do a depth-first search, that is, call the function for the directory itself only after handling the contents of the directory and its subdirectories. __FTW_MOUNT__ If set, stay within the same file system. __FTW_PHYS__ If set, do not follow symbolic links. (This is what you want.) If not set, symbolic links are followed, but no file is reported twice. If FTW_PHYS is not set, but FTW_DEPTH is set, then the function ''fn''() is never called for a directory that would be a descendant of itself. The function ''fn''() is called with four arguments: the pathname of the reported entry, a pointer to a struct stat for this entry, an integer describing its type, and a pointer to a struct FTW. The type will be one of the following: FTW_F, FTW_D, FTW_DNR, FTW_SL, FTW_NS (with meaning as above; FTW_SL occurs only with FTW_PHYS set) or __FTW_DP__ Item is a directory and all its descendants have been handled already. (This occurs only with FTW_DEPTH set.) __FTW_SLN__ Item is a symbolic link pointing to a nonexisting file. (This occurs only with FTW_PHYS unset.) The struct FTW pointed at by the fourth argument to ''fn''() has at least the fields ''base'', the offset of the item's filename in the pathname given as first argument of ''fn''(), and ''level'', the depth of the item relative to the starting point (which has depth 0). !!NOTES The function ''nftw''() and the use of FTW_SL with ''ftw''() were introduced in XPG4v2. Under Linux, libc4 and libc5 and glibc 2.0.6 will use FTW_F for all objects (files, symbolic links, fifos, etc) that can be stat'ed but are not a directory. First glibc 2.1 supports FTW_SL and ''nftw''(). !!CONFORMING TO AES, SVID2, SVID3, XPG2, XPG3, XPG4, XPG4v2. !!SEE ALSO stat(2) ----
One page links to
nftw(3)
:
Man3n
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.