FTW

Section: Linux Programmer's Manual (3)
Updated: July 18, 1993
Index Return to Main Contents
 

NAME

ftw - file tree walk  

SYNOPSIS

#include <ftw.h>

int ftw(const char *directory, int (*funcptr )(const char *file, struct stat *sb, int flag), int depth);  

DESCRIPTION

ftw() walks through the directory tree starting from the indicated directory. For each found entry in the tree, it calls funcptr with the full pathname of the entry relative to directory, a pointer to a the second argument is a pointer to the stat(2) structure for the entry and an int, which value will be one of the following:
FTW_F     Item is a normal file
FTW_D     Item is a directory
FTW_NS    The stat failed on the item
FTW_DNR   Item is a directory which can't be read
Warning: Anything other than directories, like symbolic links, gets the FTW_F tag.

ftw() recursively calls itself for traversing found directories. 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.

To stop the tree walk, funcptr returns a non-zero value; this value will become the return value of ftp(). Otherwise, ftw() will continue until it has traversed the entire tree, in which case it will return zero, or until it hits an error such as a malloc(3) failure, in which case it will return -1.

Because ftp() 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.  

SEE ALSO

stat(2)


 

Index

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 12:22:58 GMT, March 22, 2025