Products
and Services Support
and Docs Training Partner Programs About Red
Hat
  download storecart
red hat logo
redhat.comredhat network

Red Hat Documentation: man pages: man3: Linux Programmer's Manual (3)

Manpage of FTW

FTW

Section: Linux Programmer's Manual (3)
Updated: July 18, 2025
Index  

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 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 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 such as a 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 unless the program is going to terminate.  

CONFORMING TO

AES, SVID2, SVID3, XPG2, XPG3, XPG4  

SEE ALSO


 

Index

NAME
SYNOPSIS
DESCRIPTION
CONFORMING TO
SEE ALSO

This document was created by using the manual pages.
Time: 11:58:03 GMT, March 24, 2025

 

 


 
© 2001 Red Hat, Inc. All rights reserved.
About Red Hat  :  Legal statement  :  Privacy statement  :  Y2K statement  :  Contact Red Hat