ftw.3
上传用户:zibowangxu
上传日期:2007-01-04
资源大小:331k
文件大小:5k
- ."
- ." Copyright (c) 1999 WU-FTPD Development Group.
- ." All rights reserved.
- ."
- ." Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994
- ." The Regents of the University of California. Portions Copyright (c)
- ." 1993, 1994 Washington University in Saint Louis. Portions Copyright
- ." (c) 1996, 1998 Berkeley Software Design, Inc. Portions Copyright (c)
- ." 1998 Sendmail, Inc. Portions Copyright (c) 1983, 1995, 1996, 1997 Eric
- ." P. Allman. Portions Copyright (c) 1989 Massachusetts Institute of
- ." Technology. Portions Copyright (c) 1997 Stan Barber. Portions
- ." Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997 Free Software
- ." Foundation, Inc. Portions Copyright (c) 1997 Kent Landfield.
- ."
- ." Use and distribution of this software and its source code are governed
- ." by the terms and conditions of the WU-FTPD Software License ("LICENSE").
- ."
- ." $Id: ftw.3,v 1.3 1999/08/27 14:45:11 wuftpd Exp $
- ."
- .TH TREEWALK 3 August 4, 1988
- .UC 4
- .SH NAME
- ftw, treewalk - tree walk
- .SH SYNOPSIS
- .nf
- .B #include <ftw.h>
- .PP
- .B ftw(path, function, maxfds)
- .B char *path;
- .B int (*function)(), maxfds;
- .B treewalk(path, function, maxfds, options)
- .B char *path;
- .B int (*function)(), maxfds, options;
- .fi
- .SH DESCRIPTION
- .PP
- The fItreewalkfP call descends the directory hierarchy rooted in
- fIpathfP, visiting each node in turn. Visiting a node consists of
- calling the routine fIfunctionfP with three arguments. The first
- is the current path name, the second a pointer to a stat structure
- containing information about the path name, and the third a flag
- value. The declaration of the function may be as follows:
- .nf
- #include <sys/stat.h>
- function(path, st, flag)
- char *path;
- struct stat *st;
- int flag;
- .fi
- .PP
- The fIflagfP value will be one the following values, as specified in
- <fIftw.hfP>.
- .PP
- .RS
- FTW_F a regular file
- FTW_D a directory
- FTW_D2 second visit to a directory
- FTW_DNR an unreadable directory
- FTW_NS an unknown type, the stat failed
- .RE
- .PP
- If the flag value is fIFTW_NSfP, the contents of the stat buffer are
- undefined.
- .PP
- fIMaxfdsfP governs the number of file descriptors that fItreewalkfP may
- use. If passed as -1, no limit is set. Unless fIfunctionfP needs
- to open files, -1 is the suggested behavior.
- .PP
- fIOptionsfP is a bit mask which changes the behavior of fItreewalkfP.
- Its value is set by or'ing together any of the following values specified
- in <fIftw.hfP>.
- .PP
- .RS
- FTW_CHDIR fItreewalkfP may change directories
- FTW_DIRLAST visit the node after its descendents
- FTW_SYMLINK follow symbolic links
- .RE
- .PP
- fIFTW_CHDIRfP allows fItreewalkfP to descend the tree using the
- fIchdirfP(2) system call. This makes fItreewalkfP run much faster.
- A side effect of this flag is that all path names passed to fIfunctionfP
- are relative, not absolute.
- .PP
- By default, fItreewalkfP does a depth-first search, visiting each node
- before any of its descendents. If fIfunctionfP returns any other value
- than 0 or -1, fItreewalkfP will not continue, but will return this value
- to its caller. If the returned value is -1, fItreewalkfP will continue,
- but no descendents of the current node will be visited. The
- fIFTW_DIRLASTfP flag causes fItreewalkfP to visit the node again after
- all of its descendents have been visited. The second visit to the directory
- will call fIfunctionfP with the fIFTW_D2fP flag instead of fIFTW_DfP.
- .PP
- If fIFTW_SYMLINKfP is set, fItreewalkfP will pass the result of a
- fIstatfP(2) call to fIfunctionfP, rather than an fIlstatfP(2) call.
- In the case of symbolic links pointing to directories, fItreewalkfP
- will continue down the directory tree pointed to by the link. If
- fItreewalkfP is unable to indirect through the link, the node will
- be ignored and fIfunctionfP will not be called. It should also be
- noted that if the symbolic links form a loop, fItreewalkfP will not
- detect this condition.
- .PP
- If fItreewalkfP detects any error other than EACCES (see fIFTW_NSfP,
- fIFTW_DNRfP, and fIFTW_CHDIRfP, above) or EMFILE (in the case of
- running out of file descriptors) it returns -1 to its caller, leaving
- fIerrnofP unchanged.
- .SH BUGS
- The fIpathfP string passed to fIfunctionfP is the buffer currently
- being processed by fItreewalkfP and must therefore be copied before
- any modifications are made.
- .SH HISTORY
- The fItreewalkfP routine is a superset of the fIftwfP routine as
- provided by System V. fIFtwfP is available for compatibility.
- .SH SEE ALSO
- find(1), getdtablesize(2), stat(2), symlink(2), glob(3)