using ftw()


 
Thread Tools Search this Thread
Top Forums Programming using ftw()
# 1  
Old 04-03-2004
using ftw()

hello

im trying to find more information about the function: ftw()

however it seems every resource has the same thing
how to declare it and what it is supposed to do

does anyone know of a resource that actually has ftw used within a program, so i can get an idea of how to actually use it?

im concerned with such little documentation out there
if i should be using it or if there is a better way to search a directory hierarchy.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

find depth using ftw

Hello, I am looking for specific files in my tree directory using ftw(3). How do I know how deep I am in the file structure.. in other words, say I am looking for config.txt files, and my structure looks like this.. /some/directory/user1/config.txt /some/directory/user2/config.txt ....... (2 Replies)
Discussion started by: germallon
2 Replies

2. Programming

ftw/nftw -- filesystem tree walk

Hi, I recently experimented with ftw() and nftw(). These are function for calling some function for every file in a subtree. I need to get full information about type of file. Almost everything is working according to documentation but I noticed following problem: With a value FTW_PHYS... (2 Replies)
Discussion started by: odys
2 Replies

3. Programming

ftw function

int ftw(const char *path, int(*func)(), int depth); what does the third parameter(depth) mean? the book said that the larger the value of depth, the fewer directories have to be reopened, therefore increasing the speed of the call. how so? thanks (1 Reply)
Discussion started by: bb00y
1 Replies
Login or Register to Ask a Question
ftw(3)							     Library Functions Manual							    ftw(3)

NAME
ftw - Walks a file tree LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <ftw.h> int ftw( const char *path, int(*function)(const char *, const struct stat *, int), int ndirs); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: ftw(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the directory hierarchy to be searched. Specifies the function to be invoked for each object in the directory hierarchy. Speci- fies the maximum number of directory streams or file descriptors (or both) available for use by ftw(. This parameter is not used in Tru64 UNIX implementations of ftw(). This parameter must be in the range of 1 to OPEN_MAX. For backward compatibility with operating system versions prior to DIGITAL UNIX Version 4.O, ftw() takes a depth argument instead of ndirs. The depth parameter specifies the directory depth for the search, but it is not used. DESCRIPTION
The ftw() function recursively searches the directory hierarchy that descends from the directory specified by the path parameter. For each object in the hierarchy, the ftw() function calls the function specified by the function parameter, passes it a pointer to a null- terminated character string containing the name of the file, a pointer to a stat structure containing information about the file, and an integer. (See the stat(2) reference page for more information about this structure.) The integer passed to the function parameter identifies the file type or condition of the object, and it has one of the following values: A directory. A directory that cannot be read. A regular file. A file, other than a symbolic link, for which the stat() function failed. For example, FTW_NS is passed to function when a file is in a directory with read permission, but without execute (search) permission. A symbolic link. If the integer is FTW_DNR, then the files and subdirectories contained in that directory are not processed. If the integer is FTW_NS, then the stat structure contents are meaningless. The ftw() function finishes processing a directory before processing any of its files or subdirectories. The ftw() function uses at most one file descriptor for each level in the directory hierarchy. The ftw() function continues the search until the directory hierarchy specified by the path parameter is completed, an invocation of the function specified by the function parameter returns a nonzero value, or an error other than [EACCES] is detected within the ftw() function (such as an I/O error). The ndirs parameter specifies the maximum number of directory streams or file descriptors (or both) available for use by the ftw() function while traversing the directory hierarchy. When ftw() returns it closes any directory streams and file descriptors it uses not counting any opened by the application-supplied function. The ftw() function traverses symbolic links encountered in the resolution of path, including the final component. Symbolic links encoun- tered while walking the directory tree rooted at path are not traversed. NOTES
[Tru64 UNIX] When compiled in the X/Open UNIX environment, calls to the ftw() function are internally renamed by prepending _E to the function name. When debugging a module that includes the ftw() function and for which _XOPEN_SOURCE_EXTENDED has been defined, use _Eftw to refer to the ftw() call. See standards(5) for information on when the _XOPEN_SOURCE_EXTENDED macro is defined. [Tru64 UNIX] The ftw() function is reentrant; care should be taken to ensure that the function supplied as argument function is also reen- trant. Because the ftw() function is recursive, it is possible for it to terminate with a memory fault due to stack overflow when applied to very deep file structures. The ftw() function uses the malloc() function to allocate dynamic storage during its operation. If the ftw() function is terminated prior to its completion, such as by the longjmp() function being executed by the function specified by the function parameter or by an interrupt routine, the ftw() function cannot free that storage. The storage remains allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and arrange to have the function specified by the function parameter return a nonzero value the next time it is called. RETURN VALUES
If the directory hierarchy is completed, the ftw() function returns a value of 0 (zero). If the function specified by the function parameter returns a nonzero value, the ftw() function stops the search and returns the value that was returned by the function. If the ftw() function detects an error other than [EACCES], a value of -1 is returned, and errno is set to indicate the error. ERRORS
If any of the following conditions occurs, the ftw() function sets errno to the value that corresponds to the condition. Search permission is denied for any component of the path parameter or read permission is denied for the path parameter. Too many symbolic links were encountered. The length of the path string exceeds PATH_MAX, or a pathname component is longer than NAME_MAX while _POSIX_NO_TRUNC is in effect. Pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX. The path parameter points to the name of a file that does not exist or points to an empty string. A component of the path parameter is not a directory. [Tru64 UNIX] There is insufficient memory for this operation. In addition, if the function pointed to by the function parameter encounters an error, errno may be set accordingly. RELATED INFORMATION
Functions: stat(2), nftw(3) Standards: standards(5) delim off ftw(3)