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

📄 fts.3

📁 早期freebsd实现
💻 3
📖 第 1 页 / 共 2 页
字号:
.\" Copyright (c) 1989, 1991, 1993, 1994.\"	The Regents of the University of California.  All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"     @(#)fts.3	8.5 (Berkeley) 4/16/94.\".Dd April 16, 1994.Dt FTS 3.Os.Sh NAME.Nm fts.Nd traverse a file hierarchy.Sh SYNOPSIS.Fd #include <sys/types.h>.Fd #include <sys/stat.h>.Fd #include <fts.h>.Ft FTS *.Fn fts_open "char * const *path_argv" "int options" "int *compar(const FTSENT **, const FTSENT **)".Ft FTSENT *.Fn fts_read "FTS *ftsp".Ft FTSENT *.Fn fts_children "FTS *ftsp" "int options".Ft int.Fn fts_set "FTS ftsp" "FTSENT *f" "int options".Ft int.Fn fts_close "FTS *ftsp".Sh DESCRIPTIONThe.Nm ftsfunctions are provided for traversing.Tn UNIXfile hierarchies.A simple overview is that the.Fn fts_openfunction returns a ``handle'' on a file hierarchy, which is then supplied tothe other.Nm ftsfunctions.The function.Fn fts_readreturns a pointer to a structure describing one of the files in the filehierarchy.The function.Fn fts_childrenreturns a pointer to a linked list of structures, each of which describesone of the files contained in a directory in the hierarchy.In general, directories are visited two distinguishable times; in pre-order(before any of their descendants are visited) and in post-order (after allof their descendants have been visited).Files are visited once.It is possible to walk the hierarchy ``logically'' (ignoring symbolic links)or physically (visiting symbolic links), order the walk of the hierarchy orprune and/or re-visit portions of the hierarchy..PpTwo structures are defined (and typedef'd) in the include file.Aq Pa fts.h .The first is.Fa FTS ,the structure that represents the file hierarchy itself.The second is.Fa FTSENT ,the structure that represents a file in the filehierarchy.Normally, an.Fa FTSENTstructure is returned for every file in the filehierarchy.In this manual page, ``file'' and.Dq Fa FTSENT No structureare generallyinterchangeable.The.Fa FTSENTstructure contains at least the following fields, which aredescribed in greater detail below:.Bd -literaltypedef struct _ftsent {	u_short fts_info;		/* flags for FTSENT structure */	char *fts_accpath;		/* access path */	char *fts_path;			/* root path */	short fts_pathlen;		/* strlen(fts_path) */	char *fts_name;			/* file name */	short fts_namelen;		/* strlen(fts_name) */	short fts_level;		/* depth (\-1 to N) */	int fts_errno;			/* file errno */	long fts_number;		/* local numeric value */	void *fts_pointer;		/* local address value */	struct ftsent *fts_parent;	/* parent directory */	struct ftsent *fts_link;	/* next file structure */	struct ftsent *fts_cycle;	/* cycle structure */	struct stat *fts_statp;		/* stat(2) information */} FTSENT;.Ed.PpThese fields are defined as follows:.Bl -tag -width "fts_namelen".It Fa fts_infoOne of the following flags describing the returned.Fa FTSENTstructure andthe file it represents.With the exception of directories without errors.Pq Dv FTS_D ,all of theseentries are terminal, that is, they will not be revisited, nor will anyof their descendants be visited..Bl  -tag -width FTS_DEFAULT.It Dv FTS_DA directory being visited in pre-order..It Dv FTS_DCA directory that causes a cycle in the tree.(The.Fa fts_cyclefield of the.Fa FTSENTstructure will be filled in as well.).It Dv FTS_DEFAULTAny.Fa FTSENTstructure that represents a file type not explicitly describedby one of the other.Fa fts_infovalues..It Dv FTS_DNRA directory which cannot be read.This is an error return, and the.Fa fts_errnofield will be set to indicate what caused the error..It Dv FTS_DOTA file named.Ql \&.or.Ql ..which was not specified as a file name to.Fn fts_open(see.Dv FTS_SEEDOT ) ..It Dv FTS_DPA directory being visited in post-order.The contents of the.Fa FTSENTstructure will be unchanged from whenit was returned in pre-order, i.e. with the.Fa fts_infofield set to.Dv FTS_D ..It Dv FTS_ERRThis is an error return, and the.Fa fts_errnofield will be set to indicate what caused the error..It Dv FTS_FA regular file..It Dv FTS_NSA file for which no.Xr stat 2information was available.The contents of the.Fa fts_statpfield are undefined.This is an error return, and the.Fa fts_errnofield will be set to indicate what caused the error..It Dv FTS_NSOKA file for which no.Xr stat 2information was requested.The contents of the.Fa fts_statpfield are undefined..It Dv FTS_SLA symbolic link..It Dv FTS_SLNONEA symbolic link with a non-existent target.The contents of the.Fa fts_statpfield reference the file characteristic information for the symbolic linkitself..El.It Fa fts_accpathA path for accessing the file from the current directory..It Fa fts_pathThe path for the file relative to the root of the traversal.This path contains the path specified to.Fn fts_openas a prefix..It Fa fts_pathlenThe length of the string referenced by.Fa fts_path ..It Fa fts_nameThe name of the file..It Fa fts_namelenThe length of the string referenced by.Fa fts_name ..It Fa fts_levelThe depth of the traversal, numbered from \-1 to N, where this filewas found.The.Fa FTSENTstructure representing the parent of the starting point (or root)of the traversal is numbered \-1, and the.Fa FTSENTstructure for the rootitself is numbered 0..It Fa fts_errnoUpon return of a.Fa FTSENTstructure from the.Fn fts_childrenor.Fn fts_readfunctions, with its.Fa fts_infofield set to .Dv FTS_DNR ,.Dv FTS_ERRor.Dv FTS_NS ,the.Fa fts_errnofield contains the value of the external variable.Va errnospecifying the cause of the error.Otherwise, the contents of the.Fa fts_errnofield are undefined..It Fa fts_numberThis field is provided for the use of the application program and isnot modified by the.Nm ftsfunctions.It is initialized to 0..It Fa fts_pointerThis field is provided for the use of the application program and isnot modified by the.Nm ftsfunctions.It is initialized to.Dv NULL ..It Fa fts_parentA pointer to the.Fa FTSENTstructure referencing the file in the hierarchyimmediately above the current file, i.e. the directory of which thisfile is a member.A parent structure for the initial entry point is provided as well,however, only the.Fa fts_level ,.Fa fts_numberand.Fa fts_pointerfields are guaranteed to be initialized..It Fa fts_linkUpon return from the.Fn fts_childrenfunction, the.Fa fts_linkfield points to the next structure in the NULL-terminated linked list ofdirectory members.Otherwise, the contents of the.Fa fts_linkfield are undefined..It Fa fts_cycleIf a directory causes a cycle in the hierarchy (see.Dv FTS_DC ) ,either becauseof a hard link between two directories, or a symbolic link pointing to adirectory, the.Fa fts_cyclefield of the structure will point to the.Fa FTSENTstructure in the hierarchy that references the same file as the current.Fa FTSENTstructure.Otherwise, the contents of the.Fa fts_cyclefield are undefined..It Fa fts_statpA pointer to.Xr stat 2information for the file..El.PpA single buffer is used for all of the paths of all of the files in thefile hierarchy.Therefore, the.Fa fts_pathand.Fa fts_accpathfields are guaranteed to be.Dv NULL Ns -terminated.Em onlyfor the file most recently returned by.Fn fts_read .To use these fields to reference any files represented by other.Fa FTSENTstructures will require that the path buffer be modified using theinformation contained in that.Fa FTSENTstructure's.Fa fts_pathlenfield.Any such modifications should be undone before further calls to.Fn fts_readare attempted.The.Fa fts_namefield is always.Dv NULL Ns -terminated..Sh FTS_OPENThe.Fn fts_openfunction takes a pointer to an array of character pointers naming oneor more paths which make up a logical file hierarchy to be traversed.The array must be terminated by a.Dv NULLpointer..PpThere area number of options, at least one of which (either.Dv FTS_LOGICALor.Dv FTS_PHYSICAL )must be specified.The options are selected by.Em or Ns 'ingthe following values:.Bl -tag -width "FTS_PHYSICAL".It Dv FTS_COMFOLLOWThis option causes any symbolic link specified as a root path to befollowed immediately whether or not.Dv FTS_LOGICALis also specified..It Dv FTS_LOGICALThis option causes the.Nm ftsroutines to return.Fa FTSENTstructures for the targets of symbolic linksinstead of the symbolic links themselves.If this option is set, the only symbolic links for which.Fa FTSENTstructuresare returned to the application are those referencing non-existent files.Either.Dv FTS_LOGICALor.Dv FTS_PHYSICAL.Em must

⌨️ 快捷键说明

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