⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fts.3

📁 早期freebsd实现
💻 3
📖 第 1 页 / 共 2 页
字号:
be provided to the.Fn fts_openfunction..It Dv FTS_NOCHDIRAs a performance optimization, the.Nm ftsfunctions change directories as they walk the file hierarchy.This has the side-effect that an application cannot rely on beingin any particular directory during the traversal.The.Dv FTS_NOCHDIRoption turns off this optimization, and the.Nm ftsfunctions will not change the current directory.Note that applications should not themselves change their current directoryand try to access files unless.Dv FTS_NOCHDIRis specified and absolutepathnames were provided as arguments to.Fn fts_open ..It Dv FTS_NOSTATBy default, returned.Fa FTSENTstructures reference file characteristic information (the.Fa statpfield) for each file visited.This option relaxes that requirement as a performance optimization,allowing the.Nm ftsfunctions to set the.Fa fts_infofield to.Dv FTS_NSOKand leave the contents of the.Fa statpfield undefined..It Dv FTS_PHYSICALThis option causes the.Nm ftsroutines to return.Fa FTSENTstructures for symbolic links themselves insteadof the target files they point to.If this option is set,.Fa FTSENTstructures for all symbolic links in thehierarchy are returned to the application.Either.Dv FTS_LOGICALor.Dv FTS_PHYSICAL.Em mustbe provided to the.Fn fts_openfunction..It Dv FTS_SEEDOTBy default, unless they are specified as path arguments to.Fn fts_open ,any files named.Ql \&.or.Ql ..encountered in the file hierarchy are ignored.This option causes the.Nm ftsroutines to return.Fa FTSENTstructures for them..It Dv FTS_XDEVThis option prevents.Nm ftsfrom descending into directories that have a different device numberthan the file from which the descent began..El.PpThe argument.Fn comparspecifies a user-defined function which may be used to order the traversalof the hierarchy.Ittakes two pointers to pointers to.Fa FTSENTstructures as arguments andshould return a negative value, zero, or a positive value to indicateif the file referenced by its first argument comes before, in any orderwith respect to, or after, the file referenced by its second argument.The.Fa fts_accpath ,.Fa fts_pathand.Fa fts_pathlenfields of the.Fa FTSENTstructures may.Em neverbe used in this comparison.If the .Fa fts_infofield is set to.Dv FTS_NSor.Dv FTS_NSOK ,the.Fa fts_statpfield may not either.If the.Fn comparargument is.Dv NULL ,the directory traversal order is in the order listed in.Fa path_argvfor the root paths, and in the order listed in the directory foreverything else..Sh FTS_READThe.Fn fts_readfunction returns a pointer to an.Fa FTSENTstructure describing a file inthe hierarchy.Directories (that are readable and do not cause cycles) are visited atleast twice, once in pre-order and once in post-order.All other files are visited at least once.(Hard links between directories that do not cause cycles or symboliclinks to symbolic links may cause files to be visited more than once,or directories more than twice.).PpIf all the members of the hierarchy have been returned,.Fn fts_readreturns.Dv NULLand sets the external variable.Va errnoto 0.If an error unrelated to a file in the hierarchy occurs,.Fn fts_readreturns.Dv NULLand sets.Va errnoappropriately.If an error related to a returned file occurs, a pointer to an.Fa FTSENTstructure is returned, and.Va errnomay or may not have been set (see.Fa fts_info ) ..PpThe.Fa FTSENTstructures returned by.Fn fts_readmay be overwritten after a call to.Fn fts_closeon the same file hierarchy stream, or, after a call to.Fn fts_readon the same file hierarchy stream unless they represent a file of typedirectory, in which case they will not be overwritten until after a call to.Fn fts_readafter the.Fa FTSENTstructure has been returned by the function.Fn fts_readin post-order..Sh FTS_CHILDRENThe.Fn fts_childrenfunction returns a pointer to an.Fa FTSENTstructure describing the first entry in a NULL-terminated linked list ofthe files in the directory represented by the.Fa FTSENTstructure most recently returned by.Fn fts_read .The list is linked through the.Fa fts_linkfield of the.Fa FTSENTstructure, and is ordered by the user-specified comparison function, if any.Repeated calls to.Fn fts_childrenwill recreate this linked list..PpAs a special case, if.Fn fts_readhas not yet been called for a hierarchy,.Fn fts_childrenwill return a pointer to the files in the logical directory specified to.Fn fts_open ,i.e. the arguments specified to.Fn fts_open .Otherwise, if the.Fa FTSENTstructure most recently returned by.Fn fts_readis not a directory being visited in pre-order,or the directory does not contain any files,.Fn fts_childrenreturns.Dv NULLand sets.Va errnoto zero.If an error occurs,.Fn fts_childrenreturns.Dv NULLand sets.Va errnoappropriately..PpThe.Fa FTSENTstructures returned by.Fn fts_childrenmay be overwritten after a call to.Fn fts_children ,.Fn fts_closeor.Fn fts_readon the same file hierarchy stream..Pp.Em Optionmay be set to the following value:.Bl -tag -width FTS_NAMEONLY.It Dv FTS_NAMEONLYOnly the names of the files are needed.The contents of all the fields in the returned linked list of structuresare undefined with the exception of the.Fa fts_nameand.Fa fts_namelenfields..El.Sh FTS_SETThe function.Fn fts_setallows the user application to determine further processing for thefile.Fa fof the stream.Fa ftsp .The.Fn fts_setfunctionreturns 0 on success, and \-1 if an error occurs..Em Optionmust be set to one of the following values:.Bl -tag -width FTS_PHYSICAL.It Dv FTS_AGAINRe-visit the file; any file type may be re-visited.The next call to.Fn fts_readwill return the referenced file.The.Fa fts_statand.Fa fts_infofields of the structure will be reinitialized at that time,but no other fields will have been changed.This option is meaningful only for the most recently returnedfile from.Fn fts_read .Normal use is for post-order directory visits, where it causes thedirectory to be re-visited (in both pre and post-order) as well as allof its descendants..It Dv FTS_FOLLOWThe referenced file must be a symbolic link.If the referenced file is the one most recently returned by.Fn fts_read ,the next call to.Fn fts_readreturns the file with the.Fa fts_infoand.Fa fts_statpfields reinitialized to reflect the target of the symbolic link insteadof the symbolic link itself.If the file is one of those most recently returned by.Fn fts_children ,the.Fa fts_infoand.Fa fts_statpfields of the structure, when returned by.Fn fts_read ,will reflect the target of the symbolic link instead of the symbolic linkitself.In either case, if the target of the symbolic link does not exist thefields of the returned structure will be unchanged and the.Fa fts_infofield will be set to.Dv FTS_SLNONE ..PpIf the target of the link is a directory, the pre-order return, followedby the return of all of its descendants, followed by a post-order return,is done..It Dv FTS_SKIPNo descendants of this file are visited.The file may be one of those most recently returned by either.Fn fts_childrenor.Fn fts_read ..El.Sh FTS_CLOSEThe.Fn fts_closefunction closes a file hierarchy stream.Fa ftspand restores the current directory to the directory from which.Fn fts_openwas called to open.Fa ftsp .The.Fn fts_closefunctionreturns 0 on success, and \-1 if an error occurs..Sh ERRORSThe function.Fn fts_openmay fail and set.Va errnofor any of the errors specified for the library functions.Xr open 2and.Xr malloc 3 ..PpThe function.Fn fts_closemay fail and set.Va errnofor any of the errors specified for the library functions.Xr chdir 2and.Xr close 2 ..PpThe functions.Fn fts_readand.Fn fts_childrenmay fail and set.Va errnofor any of the errors specified for the library functions.Xr chdir 2 ,.Xr malloc 3 ,.Xr opendir 3 ,.Xr readdir 3and.Xr stat 2 ..PpIn addition,.Fn fts_children ,.Fn fts_openand.Fn fts_setmay fail and set.Va errnoas follows:.Bl -tag -width Er.It Bq Er EINVALThe options were invalid..El.Sh SEE ALSO.Xr find 1 ,.Xr chdir 2 ,.Xr stat 2 ,.Xr qsort 3.Sh STANDARDSThe.Nm ftsutility is expected to be included in a future.St -p1003.1-88revision.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -