📄 ftw.3
字号:
.\".\" Copyright (c) 1999,2000 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.4 2000/07/01 18:40:49 wuftpd Exp $.\".TH TREEWALK 3 August 4, 1988.UC 4.SH NAMEftw, 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.PPThe \fItreewalk\fP call descends the directory hierarchy rooted in\fIpath\fP, visiting each node in turn. Visiting a node consists ofcalling the routine \fIfunction\fP with three arguments. The firstis the current path name, the second a pointer to a stat structurecontaining information about the path name, and the third a flagvalue. 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.PPThe \fIflag\fP value will be one the following values, as specified in<\fIftw.h\fP>..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.PPIf the flag value is \fIFTW_NS\fP, the contents of the stat buffer areundefined..PP\fIMaxfds\fP governs the number of file descriptors that \fItreewalk\fP mayuse. If passed as -1, no limit is set. Unless \fIfunction\fP needsto open files, -1 is the suggested behavior..PP\fIOptions\fP is a bit mask which changes the behavior of \fItreewalk\fP.Its value is set by or'ing together any of the following values specifiedin <\fIftw.h\fP>..PP.RS FTW_CHDIR \fItreewalk\fP may change directories FTW_DIRLAST visit the node after its descendents FTW_SYMLINK follow symbolic links.RE.PP\fIFTW_CHDIR\fP allows \fItreewalk\fP to descend the tree using the\fIchdir\fP(2) system call. This makes \fItreewalk\fP run much faster.A side effect of this flag is that all path names passed to \fIfunction\fPare relative, not absolute..PPBy default, \fItreewalk\fP does a depth-first search, visiting each nodebefore any of its descendents. If \fIfunction\fP returns any other valuethan 0 or -1, \fItreewalk\fP will not continue, but will return this valueto its caller. If the returned value is -1, \fItreewalk\fP will continue,but no descendents of the current node will be visited. The\fIFTW_DIRLAST\fP flag causes \fItreewalk\fP to visit the node again afterall of its descendents have been visited. The second visit to the directorywill call \fIfunction\fP with the \fIFTW_D2\fP flag instead of \fIFTW_D\fP..PPIf \fIFTW_SYMLINK\fP is set, \fItreewalk\fP will pass the result of a\fIstat\fP(2) call to \fIfunction\fP, rather than an \fIlstat\fP(2) call.In the case of symbolic links pointing to directories, \fItreewalk\fPwill continue down the directory tree pointed to by the link. If\fItreewalk\fP is unable to indirect through the link, the node willbe ignored and \fIfunction\fP will not be called. It should also benoted that if the symbolic links form a loop, \fItreewalk\fP will notdetect this condition..PPIf \fItreewalk\fP detects any error other than EACCES (see \fIFTW_NS\fP,\fIFTW_DNR\fP, and \fIFTW_CHDIR\fP, above) or EMFILE (in the case ofrunning out of file descriptors) it returns -1 to its caller, leaving\fIerrno\fP unchanged..SH BUGSThe \fIpath\fP string passed to \fIfunction\fP is the buffer currentlybeing processed by \fItreewalk\fP and must therefore be copied beforeany modifications are made..SH HISTORYThe \fItreewalk\fP routine is a superset of the \fIftw\fP routine asprovided by System V. \fIFtw\fP is available for compatibility..SH SEE ALSOfind(1), getdtablesize(2), stat(2), symlink(2), glob(3)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -