158f0484fSRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993, 1994 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 658f0484fSRodney W. Grimes.\" are met: 758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 858f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1058f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1158f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 1358f0484fSRodney W. Grimes.\" must display the following acknowledgement: 1458f0484fSRodney W. Grimes.\" This product includes software developed by the University of 1558f0484fSRodney W. Grimes.\" California, Berkeley and its contributors. 1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 1758f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1858f0484fSRodney W. Grimes.\" without specific prior written permission. 1958f0484fSRodney W. Grimes.\" 2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3058f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3158f0484fSRodney W. Grimes.\" 3258f0484fSRodney W. Grimes.\" @(#)fts.3 8.5 (Berkeley) 4/16/94 332d386814SMike Pritchard.\" $Id$ 3458f0484fSRodney W. Grimes.\" 3558f0484fSRodney W. Grimes.Dd April 16, 1994 3658f0484fSRodney W. Grimes.Dt FTS 3 3758f0484fSRodney W. Grimes.Os 3858f0484fSRodney W. Grimes.Sh NAME 3958f0484fSRodney W. Grimes.Nm fts 4058f0484fSRodney W. Grimes.Nd traverse a file hierarchy 4158f0484fSRodney W. Grimes.Sh SYNOPSIS 4258f0484fSRodney W. Grimes.Fd #include <sys/types.h> 4358f0484fSRodney W. Grimes.Fd #include <sys/stat.h> 4458f0484fSRodney W. Grimes.Fd #include <fts.h> 4558f0484fSRodney W. Grimes.Ft FTS * 467a6b3357SJohn Polstra.Fn fts_open "char * const *path_argv" "int options" "int (*compar)(const FTSENT **, const FTSENT **)" 4758f0484fSRodney W. Grimes.Ft FTSENT * 4858f0484fSRodney W. Grimes.Fn fts_read "FTS *ftsp" 4958f0484fSRodney W. Grimes.Ft FTSENT * 5058f0484fSRodney W. Grimes.Fn fts_children "FTS *ftsp" "int options" 5158f0484fSRodney W. Grimes.Ft int 522d386814SMike Pritchard.Fn fts_set "FTS *ftsp" "FTSENT *f" "int options" 5358f0484fSRodney W. Grimes.Ft int 5458f0484fSRodney W. Grimes.Fn fts_close "FTS *ftsp" 5558f0484fSRodney W. Grimes.Sh DESCRIPTION 5658f0484fSRodney W. GrimesThe 5758f0484fSRodney W. Grimes.Nm fts 5858f0484fSRodney W. Grimesfunctions are provided for traversing 5958f0484fSRodney W. Grimes.Tn UNIX 6058f0484fSRodney W. Grimesfile hierarchies. 6158f0484fSRodney W. GrimesA simple overview is that the 6258f0484fSRodney W. Grimes.Fn fts_open 6358f0484fSRodney W. Grimesfunction returns a ``handle'' on a file hierarchy, which is then supplied to 6458f0484fSRodney W. Grimesthe other 6558f0484fSRodney W. Grimes.Nm fts 6658f0484fSRodney W. Grimesfunctions. 6758f0484fSRodney W. GrimesThe function 6858f0484fSRodney W. Grimes.Fn fts_read 6958f0484fSRodney W. Grimesreturns a pointer to a structure describing one of the files in the file 7058f0484fSRodney W. Grimeshierarchy. 7158f0484fSRodney W. GrimesThe function 7258f0484fSRodney W. Grimes.Fn fts_children 7358f0484fSRodney W. Grimesreturns a pointer to a linked list of structures, each of which describes 7458f0484fSRodney W. Grimesone of the files contained in a directory in the hierarchy. 7558f0484fSRodney W. GrimesIn general, directories are visited two distinguishable times; in pre-order 7658f0484fSRodney W. Grimes(before any of their descendants are visited) and in post-order (after all 7758f0484fSRodney W. Grimesof their descendants have been visited). 7858f0484fSRodney W. GrimesFiles are visited once. 7958f0484fSRodney W. GrimesIt is possible to walk the hierarchy ``logically'' (ignoring symbolic links) 8058f0484fSRodney W. Grimesor physically (visiting symbolic links), order the walk of the hierarchy or 8158f0484fSRodney W. Grimesprune and/or re-visit portions of the hierarchy. 8258f0484fSRodney W. Grimes.Pp 8358f0484fSRodney W. GrimesTwo structures are defined (and typedef'd) in the include file 8458f0484fSRodney W. Grimes.Aq Pa fts.h . 8558f0484fSRodney W. GrimesThe first is 8658f0484fSRodney W. Grimes.Fa FTS , 8758f0484fSRodney W. Grimesthe structure that represents the file hierarchy itself. 8858f0484fSRodney W. GrimesThe second is 8958f0484fSRodney W. Grimes.Fa FTSENT , 9058f0484fSRodney W. Grimesthe structure that represents a file in the file 9158f0484fSRodney W. Grimeshierarchy. 9258f0484fSRodney W. GrimesNormally, an 9358f0484fSRodney W. Grimes.Fa FTSENT 9458f0484fSRodney W. Grimesstructure is returned for every file in the file 9558f0484fSRodney W. Grimeshierarchy. 9658f0484fSRodney W. GrimesIn this manual page, ``file'' and 9758f0484fSRodney W. Grimes.Dq Fa FTSENT No structure 9858f0484fSRodney W. Grimesare generally 9958f0484fSRodney W. Grimesinterchangeable. 10058f0484fSRodney W. GrimesThe 10158f0484fSRodney W. Grimes.Fa FTSENT 10258f0484fSRodney W. Grimesstructure contains at least the following fields, which are 10358f0484fSRodney W. Grimesdescribed in greater detail below: 10458f0484fSRodney W. Grimes.Bd -literal 10558f0484fSRodney W. Grimestypedef struct _ftsent { 10658f0484fSRodney W. Grimes u_short fts_info; /* flags for FTSENT structure */ 10758f0484fSRodney W. Grimes char *fts_accpath; /* access path */ 10858f0484fSRodney W. Grimes char *fts_path; /* root path */ 10958f0484fSRodney W. Grimes short fts_pathlen; /* strlen(fts_path) */ 11058f0484fSRodney W. Grimes char *fts_name; /* file name */ 11158f0484fSRodney W. Grimes short fts_namelen; /* strlen(fts_name) */ 11258f0484fSRodney W. Grimes short fts_level; /* depth (\-1 to N) */ 11358f0484fSRodney W. Grimes int fts_errno; /* file errno */ 11458f0484fSRodney W. Grimes long fts_number; /* local numeric value */ 11558f0484fSRodney W. Grimes void *fts_pointer; /* local address value */ 11658f0484fSRodney W. Grimes struct ftsent *fts_parent; /* parent directory */ 11758f0484fSRodney W. Grimes struct ftsent *fts_link; /* next file structure */ 11858f0484fSRodney W. Grimes struct ftsent *fts_cycle; /* cycle structure */ 11958f0484fSRodney W. Grimes struct stat *fts_statp; /* stat(2) information */ 12058f0484fSRodney W. Grimes} FTSENT; 12158f0484fSRodney W. Grimes.Ed 12258f0484fSRodney W. Grimes.Pp 12358f0484fSRodney W. GrimesThese fields are defined as follows: 12458f0484fSRodney W. Grimes.Bl -tag -width "fts_namelen" 12558f0484fSRodney W. Grimes.It Fa fts_info 1267a6b3357SJohn PolstraOne of the following values describing the returned 12758f0484fSRodney W. Grimes.Fa FTSENT 12858f0484fSRodney W. Grimesstructure and 12958f0484fSRodney W. Grimesthe file it represents. 13058f0484fSRodney W. GrimesWith the exception of directories without errors 13158f0484fSRodney W. Grimes.Pq Dv FTS_D , 13258f0484fSRodney W. Grimesall of these 13358f0484fSRodney W. Grimesentries are terminal, that is, they will not be revisited, nor will any 13458f0484fSRodney W. Grimesof their descendants be visited. 13558f0484fSRodney W. Grimes.Bl -tag -width FTS_DEFAULT 13658f0484fSRodney W. Grimes.It Dv FTS_D 13758f0484fSRodney W. GrimesA directory being visited in pre-order. 13858f0484fSRodney W. Grimes.It Dv FTS_DC 13958f0484fSRodney W. GrimesA directory that causes a cycle in the tree. 14058f0484fSRodney W. Grimes(The 14158f0484fSRodney W. Grimes.Fa fts_cycle 14258f0484fSRodney W. Grimesfield of the 14358f0484fSRodney W. Grimes.Fa FTSENT 14458f0484fSRodney W. Grimesstructure will be filled in as well.) 14558f0484fSRodney W. Grimes.It Dv FTS_DEFAULT 14658f0484fSRodney W. GrimesAny 14758f0484fSRodney W. Grimes.Fa FTSENT 14858f0484fSRodney W. Grimesstructure that represents a file type not explicitly described 14958f0484fSRodney W. Grimesby one of the other 15058f0484fSRodney W. Grimes.Fa fts_info 15158f0484fSRodney W. Grimesvalues. 15258f0484fSRodney W. Grimes.It Dv FTS_DNR 15358f0484fSRodney W. GrimesA directory which cannot be read. 15458f0484fSRodney W. GrimesThis is an error return, and the 15558f0484fSRodney W. Grimes.Fa fts_errno 15658f0484fSRodney W. Grimesfield will be set to indicate what caused the error. 15758f0484fSRodney W. Grimes.It Dv FTS_DOT 15858f0484fSRodney W. GrimesA file named 15958f0484fSRodney W. Grimes.Ql \&. 16058f0484fSRodney W. Grimesor 16158f0484fSRodney W. Grimes.Ql .. 16258f0484fSRodney W. Grimeswhich was not specified as a file name to 16358f0484fSRodney W. Grimes.Fn fts_open 16458f0484fSRodney W. Grimes(see 16558f0484fSRodney W. Grimes.Dv FTS_SEEDOT ) . 16658f0484fSRodney W. Grimes.It Dv FTS_DP 16758f0484fSRodney W. GrimesA directory being visited in post-order. 16858f0484fSRodney W. GrimesThe contents of the 16958f0484fSRodney W. Grimes.Fa FTSENT 17058f0484fSRodney W. Grimesstructure will be unchanged from when 17158f0484fSRodney W. Grimesit was returned in pre-order, i.e. with the 17258f0484fSRodney W. Grimes.Fa fts_info 17358f0484fSRodney W. Grimesfield set to 17458f0484fSRodney W. Grimes.Dv FTS_D . 17558f0484fSRodney W. Grimes.It Dv FTS_ERR 17658f0484fSRodney W. GrimesThis is an error return, and the 17758f0484fSRodney W. Grimes.Fa fts_errno 17858f0484fSRodney W. Grimesfield will be set to indicate what caused the error. 17958f0484fSRodney W. Grimes.It Dv FTS_F 18058f0484fSRodney W. GrimesA regular file. 18158f0484fSRodney W. Grimes.It Dv FTS_NS 18258f0484fSRodney W. GrimesA file for which no 18358f0484fSRodney W. Grimes.Xr stat 2 18458f0484fSRodney W. Grimesinformation was available. 18558f0484fSRodney W. GrimesThe contents of the 18658f0484fSRodney W. Grimes.Fa fts_statp 18758f0484fSRodney W. Grimesfield are undefined. 18858f0484fSRodney W. GrimesThis is an error return, and the 18958f0484fSRodney W. Grimes.Fa fts_errno 19058f0484fSRodney W. Grimesfield will be set to indicate what caused the error. 19158f0484fSRodney W. Grimes.It Dv FTS_NSOK 19258f0484fSRodney W. GrimesA file for which no 19358f0484fSRodney W. Grimes.Xr stat 2 19458f0484fSRodney W. Grimesinformation was requested. 19558f0484fSRodney W. GrimesThe contents of the 19658f0484fSRodney W. Grimes.Fa fts_statp 19758f0484fSRodney W. Grimesfield are undefined. 19858f0484fSRodney W. Grimes.It Dv FTS_SL 19958f0484fSRodney W. GrimesA symbolic link. 20058f0484fSRodney W. Grimes.It Dv FTS_SLNONE 20158f0484fSRodney W. GrimesA symbolic link with a non-existent target. 20258f0484fSRodney W. GrimesThe contents of the 20358f0484fSRodney W. Grimes.Fa fts_statp 20458f0484fSRodney W. Grimesfield reference the file characteristic information for the symbolic link 20558f0484fSRodney W. Grimesitself. 20658f0484fSRodney W. Grimes.El 20758f0484fSRodney W. Grimes.It Fa fts_accpath 20858f0484fSRodney W. GrimesA path for accessing the file from the current directory. 20958f0484fSRodney W. Grimes.It Fa fts_path 21058f0484fSRodney W. GrimesThe path for the file relative to the root of the traversal. 21158f0484fSRodney W. GrimesThis path contains the path specified to 21258f0484fSRodney W. Grimes.Fn fts_open 21358f0484fSRodney W. Grimesas a prefix. 21458f0484fSRodney W. Grimes.It Fa fts_pathlen 21558f0484fSRodney W. GrimesThe length of the string referenced by 21658f0484fSRodney W. Grimes.Fa fts_path . 21758f0484fSRodney W. Grimes.It Fa fts_name 21858f0484fSRodney W. GrimesThe name of the file. 21958f0484fSRodney W. Grimes.It Fa fts_namelen 22058f0484fSRodney W. GrimesThe length of the string referenced by 22158f0484fSRodney W. Grimes.Fa fts_name . 22258f0484fSRodney W. Grimes.It Fa fts_level 22358f0484fSRodney W. GrimesThe depth of the traversal, numbered from \-1 to N, where this file 22458f0484fSRodney W. Grimeswas found. 22558f0484fSRodney W. GrimesThe 22658f0484fSRodney W. Grimes.Fa FTSENT 22758f0484fSRodney W. Grimesstructure representing the parent of the starting point (or root) 22858f0484fSRodney W. Grimesof the traversal is numbered \-1, and the 22958f0484fSRodney W. Grimes.Fa FTSENT 23058f0484fSRodney W. Grimesstructure for the root 23158f0484fSRodney W. Grimesitself is numbered 0. 23258f0484fSRodney W. Grimes.It Fa fts_errno 23358f0484fSRodney W. GrimesUpon return of a 23458f0484fSRodney W. Grimes.Fa FTSENT 23558f0484fSRodney W. Grimesstructure from the 23658f0484fSRodney W. Grimes.Fn fts_children 23758f0484fSRodney W. Grimesor 23858f0484fSRodney W. Grimes.Fn fts_read 23958f0484fSRodney W. Grimesfunctions, with its 24058f0484fSRodney W. Grimes.Fa fts_info 24158f0484fSRodney W. Grimesfield set to 24258f0484fSRodney W. Grimes.Dv FTS_DNR , 24358f0484fSRodney W. Grimes.Dv FTS_ERR 24458f0484fSRodney W. Grimesor 24558f0484fSRodney W. Grimes.Dv FTS_NS , 24658f0484fSRodney W. Grimesthe 24758f0484fSRodney W. Grimes.Fa fts_errno 24858f0484fSRodney W. Grimesfield contains the value of the external variable 24958f0484fSRodney W. Grimes.Va errno 25058f0484fSRodney W. Grimesspecifying the cause of the error. 25158f0484fSRodney W. GrimesOtherwise, the contents of the 25258f0484fSRodney W. Grimes.Fa fts_errno 25358f0484fSRodney W. Grimesfield are undefined. 25458f0484fSRodney W. Grimes.It Fa fts_number 25558f0484fSRodney W. GrimesThis field is provided for the use of the application program and is 25658f0484fSRodney W. Grimesnot modified by the 25758f0484fSRodney W. Grimes.Nm fts 25858f0484fSRodney W. Grimesfunctions. 25958f0484fSRodney W. GrimesIt is initialized to 0. 26058f0484fSRodney W. Grimes.It Fa fts_pointer 26158f0484fSRodney W. GrimesThis field is provided for the use of the application program and is 26258f0484fSRodney W. Grimesnot modified by the 26358f0484fSRodney W. Grimes.Nm fts 26458f0484fSRodney W. Grimesfunctions. 26558f0484fSRodney W. GrimesIt is initialized to 26658f0484fSRodney W. Grimes.Dv NULL . 26758f0484fSRodney W. Grimes.It Fa fts_parent 26858f0484fSRodney W. GrimesA pointer to the 26958f0484fSRodney W. Grimes.Fa FTSENT 27058f0484fSRodney W. Grimesstructure referencing the file in the hierarchy 27158f0484fSRodney W. Grimesimmediately above the current file, i.e. the directory of which this 27258f0484fSRodney W. Grimesfile is a member. 27358f0484fSRodney W. GrimesA parent structure for the initial entry point is provided as well, 27458f0484fSRodney W. Grimeshowever, only the 27558f0484fSRodney W. Grimes.Fa fts_level , 27658f0484fSRodney W. Grimes.Fa fts_number 27758f0484fSRodney W. Grimesand 27858f0484fSRodney W. Grimes.Fa fts_pointer 27958f0484fSRodney W. Grimesfields are guaranteed to be initialized. 28058f0484fSRodney W. Grimes.It Fa fts_link 28158f0484fSRodney W. GrimesUpon return from the 28258f0484fSRodney W. Grimes.Fn fts_children 28358f0484fSRodney W. Grimesfunction, the 28458f0484fSRodney W. Grimes.Fa fts_link 28558f0484fSRodney W. Grimesfield points to the next structure in the NULL-terminated linked list of 28658f0484fSRodney W. Grimesdirectory members. 28758f0484fSRodney W. GrimesOtherwise, the contents of the 28858f0484fSRodney W. Grimes.Fa fts_link 28958f0484fSRodney W. Grimesfield are undefined. 29058f0484fSRodney W. Grimes.It Fa fts_cycle 29158f0484fSRodney W. GrimesIf a directory causes a cycle in the hierarchy (see 29258f0484fSRodney W. Grimes.Dv FTS_DC ) , 29358f0484fSRodney W. Grimeseither because 29458f0484fSRodney W. Grimesof a hard link between two directories, or a symbolic link pointing to a 29558f0484fSRodney W. Grimesdirectory, the 29658f0484fSRodney W. Grimes.Fa fts_cycle 29758f0484fSRodney W. Grimesfield of the structure will point to the 29858f0484fSRodney W. Grimes.Fa FTSENT 29958f0484fSRodney W. Grimesstructure in the hierarchy that references the same file as the current 30058f0484fSRodney W. Grimes.Fa FTSENT 30158f0484fSRodney W. Grimesstructure. 30258f0484fSRodney W. GrimesOtherwise, the contents of the 30358f0484fSRodney W. Grimes.Fa fts_cycle 30458f0484fSRodney W. Grimesfield are undefined. 30558f0484fSRodney W. Grimes.It Fa fts_statp 30658f0484fSRodney W. GrimesA pointer to 30758f0484fSRodney W. Grimes.Xr stat 2 30858f0484fSRodney W. Grimesinformation for the file. 30958f0484fSRodney W. Grimes.El 31058f0484fSRodney W. Grimes.Pp 31158f0484fSRodney W. GrimesA single buffer is used for all of the paths of all of the files in the 31258f0484fSRodney W. Grimesfile hierarchy. 31358f0484fSRodney W. GrimesTherefore, the 31458f0484fSRodney W. Grimes.Fa fts_path 31558f0484fSRodney W. Grimesand 31658f0484fSRodney W. Grimes.Fa fts_accpath 31758f0484fSRodney W. Grimesfields are guaranteed to be 31858f0484fSRodney W. Grimes.Dv NULL Ns -terminated 31958f0484fSRodney W. Grimes.Em only 32058f0484fSRodney W. Grimesfor the file most recently returned by 32158f0484fSRodney W. Grimes.Fn fts_read . 32258f0484fSRodney W. GrimesTo use these fields to reference any files represented by other 32358f0484fSRodney W. Grimes.Fa FTSENT 32458f0484fSRodney W. Grimesstructures will require that the path buffer be modified using the 32558f0484fSRodney W. Grimesinformation contained in that 32658f0484fSRodney W. Grimes.Fa FTSENT 32758f0484fSRodney W. Grimesstructure's 32858f0484fSRodney W. Grimes.Fa fts_pathlen 32958f0484fSRodney W. Grimesfield. 33058f0484fSRodney W. GrimesAny such modifications should be undone before further calls to 33158f0484fSRodney W. Grimes.Fn fts_read 33258f0484fSRodney W. Grimesare attempted. 33358f0484fSRodney W. GrimesThe 33458f0484fSRodney W. Grimes.Fa fts_name 33558f0484fSRodney W. Grimesfield is always 33658f0484fSRodney W. Grimes.Dv NULL Ns -terminated. 33758f0484fSRodney W. Grimes.Sh FTS_OPEN 33858f0484fSRodney W. GrimesThe 33958f0484fSRodney W. Grimes.Fn fts_open 34058f0484fSRodney W. Grimesfunction takes a pointer to an array of character pointers naming one 34158f0484fSRodney W. Grimesor more paths which make up a logical file hierarchy to be traversed. 34258f0484fSRodney W. GrimesThe array must be terminated by a 34358f0484fSRodney W. Grimes.Dv NULL 34458f0484fSRodney W. Grimespointer. 34558f0484fSRodney W. Grimes.Pp 34658f0484fSRodney W. GrimesThere are 34758f0484fSRodney W. Grimesa number of options, at least one of which (either 34858f0484fSRodney W. Grimes.Dv FTS_LOGICAL 34958f0484fSRodney W. Grimesor 35058f0484fSRodney W. Grimes.Dv FTS_PHYSICAL ) 35158f0484fSRodney W. Grimesmust be specified. 35258f0484fSRodney W. GrimesThe options are selected by 35358f0484fSRodney W. Grimes.Em or Ns 'ing 35458f0484fSRodney W. Grimesthe following values: 35558f0484fSRodney W. Grimes.Bl -tag -width "FTS_PHYSICAL" 35658f0484fSRodney W. Grimes.It Dv FTS_COMFOLLOW 35758f0484fSRodney W. GrimesThis option causes any symbolic link specified as a root path to be 35858f0484fSRodney W. Grimesfollowed immediately whether or not 35958f0484fSRodney W. Grimes.Dv FTS_LOGICAL 36058f0484fSRodney W. Grimesis also specified. 36158f0484fSRodney W. Grimes.It Dv FTS_LOGICAL 36258f0484fSRodney W. GrimesThis option causes the 36358f0484fSRodney W. Grimes.Nm fts 36458f0484fSRodney W. Grimesroutines to return 36558f0484fSRodney W. Grimes.Fa FTSENT 36658f0484fSRodney W. Grimesstructures for the targets of symbolic links 36758f0484fSRodney W. Grimesinstead of the symbolic links themselves. 36858f0484fSRodney W. GrimesIf this option is set, the only symbolic links for which 36958f0484fSRodney W. Grimes.Fa FTSENT 37058f0484fSRodney W. Grimesstructures 37158f0484fSRodney W. Grimesare returned to the application are those referencing non-existent files. 37258f0484fSRodney W. GrimesEither 37358f0484fSRodney W. Grimes.Dv FTS_LOGICAL 37458f0484fSRodney W. Grimesor 37558f0484fSRodney W. Grimes.Dv FTS_PHYSICAL 37658f0484fSRodney W. Grimes.Em must 37758f0484fSRodney W. Grimesbe provided to the 37858f0484fSRodney W. Grimes.Fn fts_open 37958f0484fSRodney W. Grimesfunction. 38058f0484fSRodney W. Grimes.It Dv FTS_NOCHDIR 38158f0484fSRodney W. GrimesAs a performance optimization, the 38258f0484fSRodney W. Grimes.Nm fts 38358f0484fSRodney W. Grimesfunctions change directories as they walk the file hierarchy. 38458f0484fSRodney W. GrimesThis has the side-effect that an application cannot rely on being 38558f0484fSRodney W. Grimesin any particular directory during the traversal. 38658f0484fSRodney W. GrimesThe 38758f0484fSRodney W. Grimes.Dv FTS_NOCHDIR 38858f0484fSRodney W. Grimesoption turns off this optimization, and the 38958f0484fSRodney W. Grimes.Nm fts 39058f0484fSRodney W. Grimesfunctions will not change the current directory. 39158f0484fSRodney W. GrimesNote that applications should not themselves change their current directory 39258f0484fSRodney W. Grimesand try to access files unless 39358f0484fSRodney W. Grimes.Dv FTS_NOCHDIR 39458f0484fSRodney W. Grimesis specified and absolute 39558f0484fSRodney W. Grimespathnames were provided as arguments to 39658f0484fSRodney W. Grimes.Fn fts_open . 39758f0484fSRodney W. Grimes.It Dv FTS_NOSTAT 39858f0484fSRodney W. GrimesBy default, returned 39958f0484fSRodney W. Grimes.Fa FTSENT 40058f0484fSRodney W. Grimesstructures reference file characteristic information (the 40158f0484fSRodney W. Grimes.Fa statp 40258f0484fSRodney W. Grimesfield) for each file visited. 40358f0484fSRodney W. GrimesThis option relaxes that requirement as a performance optimization, 40458f0484fSRodney W. Grimesallowing the 40558f0484fSRodney W. Grimes.Nm fts 40658f0484fSRodney W. Grimesfunctions to set the 40758f0484fSRodney W. Grimes.Fa fts_info 40858f0484fSRodney W. Grimesfield to 40958f0484fSRodney W. Grimes.Dv FTS_NSOK 41058f0484fSRodney W. Grimesand leave the contents of the 41158f0484fSRodney W. Grimes.Fa statp 41258f0484fSRodney W. Grimesfield undefined. 41358f0484fSRodney W. Grimes.It Dv FTS_PHYSICAL 41458f0484fSRodney W. GrimesThis option causes the 41558f0484fSRodney W. Grimes.Nm fts 41658f0484fSRodney W. Grimesroutines to return 41758f0484fSRodney W. Grimes.Fa FTSENT 41858f0484fSRodney W. Grimesstructures for symbolic links themselves instead 41958f0484fSRodney W. Grimesof the target files they point to. 42058f0484fSRodney W. GrimesIf this option is set, 42158f0484fSRodney W. Grimes.Fa FTSENT 42258f0484fSRodney W. Grimesstructures for all symbolic links in the 42358f0484fSRodney W. Grimeshierarchy are returned to the application. 42458f0484fSRodney W. GrimesEither 42558f0484fSRodney W. Grimes.Dv FTS_LOGICAL 42658f0484fSRodney W. Grimesor 42758f0484fSRodney W. Grimes.Dv FTS_PHYSICAL 42858f0484fSRodney W. Grimes.Em must 42958f0484fSRodney W. Grimesbe provided to the 43058f0484fSRodney W. Grimes.Fn fts_open 43158f0484fSRodney W. Grimesfunction. 43258f0484fSRodney W. Grimes.It Dv FTS_SEEDOT 43358f0484fSRodney W. GrimesBy default, unless they are specified as path arguments to 43458f0484fSRodney W. Grimes.Fn fts_open , 43558f0484fSRodney W. Grimesany files named 43658f0484fSRodney W. Grimes.Ql \&. 43758f0484fSRodney W. Grimesor 43858f0484fSRodney W. Grimes.Ql .. 43958f0484fSRodney W. Grimesencountered in the file hierarchy are ignored. 44058f0484fSRodney W. GrimesThis option causes the 44158f0484fSRodney W. Grimes.Nm fts 44258f0484fSRodney W. Grimesroutines to return 44358f0484fSRodney W. Grimes.Fa FTSENT 44458f0484fSRodney W. Grimesstructures for them. 44558f0484fSRodney W. Grimes.It Dv FTS_XDEV 44658f0484fSRodney W. GrimesThis option prevents 44758f0484fSRodney W. Grimes.Nm fts 44858f0484fSRodney W. Grimesfrom descending into directories that have a different device number 44958f0484fSRodney W. Grimesthan the file from which the descent began. 45058f0484fSRodney W. Grimes.El 45158f0484fSRodney W. Grimes.Pp 45258f0484fSRodney W. GrimesThe argument 45358f0484fSRodney W. Grimes.Fn compar 45458f0484fSRodney W. Grimesspecifies a user-defined function which may be used to order the traversal 45558f0484fSRodney W. Grimesof the hierarchy. 45658f0484fSRodney W. GrimesIt 45758f0484fSRodney W. Grimestakes two pointers to pointers to 45858f0484fSRodney W. Grimes.Fa FTSENT 45958f0484fSRodney W. Grimesstructures as arguments and 46058f0484fSRodney W. Grimesshould return a negative value, zero, or a positive value to indicate 46158f0484fSRodney W. Grimesif the file referenced by its first argument comes before, in any order 46258f0484fSRodney W. Grimeswith respect to, or after, the file referenced by its second argument. 46358f0484fSRodney W. GrimesThe 46458f0484fSRodney W. Grimes.Fa fts_accpath , 46558f0484fSRodney W. Grimes.Fa fts_path 46658f0484fSRodney W. Grimesand 46758f0484fSRodney W. Grimes.Fa fts_pathlen 46858f0484fSRodney W. Grimesfields of the 46958f0484fSRodney W. Grimes.Fa FTSENT 47058f0484fSRodney W. Grimesstructures may 47158f0484fSRodney W. Grimes.Em never 47258f0484fSRodney W. Grimesbe used in this comparison. 47358f0484fSRodney W. GrimesIf the 47458f0484fSRodney W. Grimes.Fa fts_info 47558f0484fSRodney W. Grimesfield is set to 47658f0484fSRodney W. Grimes.Dv FTS_NS 47758f0484fSRodney W. Grimesor 47858f0484fSRodney W. Grimes.Dv FTS_NSOK , 47958f0484fSRodney W. Grimesthe 48058f0484fSRodney W. Grimes.Fa fts_statp 48158f0484fSRodney W. Grimesfield may not either. 48258f0484fSRodney W. GrimesIf the 48358f0484fSRodney W. Grimes.Fn compar 48458f0484fSRodney W. Grimesargument is 48558f0484fSRodney W. Grimes.Dv NULL , 48658f0484fSRodney W. Grimesthe directory traversal order is in the order listed in 48758f0484fSRodney W. Grimes.Fa path_argv 48858f0484fSRodney W. Grimesfor the root paths, and in the order listed in the directory for 48958f0484fSRodney W. Grimeseverything else. 49058f0484fSRodney W. Grimes.Sh FTS_READ 49158f0484fSRodney W. GrimesThe 49258f0484fSRodney W. Grimes.Fn fts_read 49358f0484fSRodney W. Grimesfunction returns a pointer to an 49458f0484fSRodney W. Grimes.Fa FTSENT 49558f0484fSRodney W. Grimesstructure describing a file in 49658f0484fSRodney W. Grimesthe hierarchy. 49758f0484fSRodney W. GrimesDirectories (that are readable and do not cause cycles) are visited at 49858f0484fSRodney W. Grimesleast twice, once in pre-order and once in post-order. 49958f0484fSRodney W. GrimesAll other files are visited at least once. 50058f0484fSRodney W. Grimes(Hard links between directories that do not cause cycles or symbolic 50158f0484fSRodney W. Grimeslinks to symbolic links may cause files to be visited more than once, 50258f0484fSRodney W. Grimesor directories more than twice.) 50358f0484fSRodney W. Grimes.Pp 50458f0484fSRodney W. GrimesIf all the members of the hierarchy have been returned, 50558f0484fSRodney W. Grimes.Fn fts_read 50658f0484fSRodney W. Grimesreturns 50758f0484fSRodney W. Grimes.Dv NULL 50858f0484fSRodney W. Grimesand sets the external variable 50958f0484fSRodney W. Grimes.Va errno 51058f0484fSRodney W. Grimesto 0. 51158f0484fSRodney W. GrimesIf an error unrelated to a file in the hierarchy occurs, 51258f0484fSRodney W. Grimes.Fn fts_read 51358f0484fSRodney W. Grimesreturns 51458f0484fSRodney W. Grimes.Dv NULL 51558f0484fSRodney W. Grimesand sets 51658f0484fSRodney W. Grimes.Va errno 51758f0484fSRodney W. Grimesappropriately. 51858f0484fSRodney W. GrimesIf an error related to a returned file occurs, a pointer to an 51958f0484fSRodney W. Grimes.Fa FTSENT 52058f0484fSRodney W. Grimesstructure is returned, and 52158f0484fSRodney W. Grimes.Va errno 52258f0484fSRodney W. Grimesmay or may not have been set (see 52358f0484fSRodney W. Grimes.Fa fts_info ) . 52458f0484fSRodney W. Grimes.Pp 52558f0484fSRodney W. GrimesThe 52658f0484fSRodney W. Grimes.Fa FTSENT 52758f0484fSRodney W. Grimesstructures returned by 52858f0484fSRodney W. Grimes.Fn fts_read 52958f0484fSRodney W. Grimesmay be overwritten after a call to 53058f0484fSRodney W. Grimes.Fn fts_close 53158f0484fSRodney W. Grimeson the same file hierarchy stream, or, after a call to 53258f0484fSRodney W. Grimes.Fn fts_read 53358f0484fSRodney W. Grimeson the same file hierarchy stream unless they represent a file of type 53458f0484fSRodney W. Grimesdirectory, in which case they will not be overwritten until after a call to 53558f0484fSRodney W. Grimes.Fn fts_read 53658f0484fSRodney W. Grimesafter the 53758f0484fSRodney W. Grimes.Fa FTSENT 53858f0484fSRodney W. Grimesstructure has been returned by the function 53958f0484fSRodney W. Grimes.Fn fts_read 54058f0484fSRodney W. Grimesin post-order. 54158f0484fSRodney W. Grimes.Sh FTS_CHILDREN 54258f0484fSRodney W. GrimesThe 54358f0484fSRodney W. Grimes.Fn fts_children 54458f0484fSRodney W. Grimesfunction returns a pointer to an 54558f0484fSRodney W. Grimes.Fa FTSENT 54658f0484fSRodney W. Grimesstructure describing the first entry in a NULL-terminated linked list of 54758f0484fSRodney W. Grimesthe files in the directory represented by the 54858f0484fSRodney W. Grimes.Fa FTSENT 54958f0484fSRodney W. Grimesstructure most recently returned by 55058f0484fSRodney W. Grimes.Fn fts_read . 55158f0484fSRodney W. GrimesThe list is linked through the 55258f0484fSRodney W. Grimes.Fa fts_link 55358f0484fSRodney W. Grimesfield of the 55458f0484fSRodney W. Grimes.Fa FTSENT 55558f0484fSRodney W. Grimesstructure, and is ordered by the user-specified comparison function, if any. 55658f0484fSRodney W. GrimesRepeated calls to 55758f0484fSRodney W. Grimes.Fn fts_children 55858f0484fSRodney W. Grimeswill recreate this linked list. 55958f0484fSRodney W. Grimes.Pp 56058f0484fSRodney W. GrimesAs a special case, if 56158f0484fSRodney W. Grimes.Fn fts_read 56258f0484fSRodney W. Grimeshas not yet been called for a hierarchy, 56358f0484fSRodney W. Grimes.Fn fts_children 56458f0484fSRodney W. Grimeswill return a pointer to the files in the logical directory specified to 56558f0484fSRodney W. Grimes.Fn fts_open , 56658f0484fSRodney W. Grimesi.e. the arguments specified to 56758f0484fSRodney W. Grimes.Fn fts_open . 56858f0484fSRodney W. GrimesOtherwise, if the 56958f0484fSRodney W. Grimes.Fa FTSENT 57058f0484fSRodney W. Grimesstructure most recently returned by 57158f0484fSRodney W. Grimes.Fn fts_read 57258f0484fSRodney W. Grimesis not a directory being visited in pre-order, 57358f0484fSRodney W. Grimesor the directory does not contain any files, 57458f0484fSRodney W. Grimes.Fn fts_children 57558f0484fSRodney W. Grimesreturns 57658f0484fSRodney W. Grimes.Dv NULL 57758f0484fSRodney W. Grimesand sets 57858f0484fSRodney W. Grimes.Va errno 57958f0484fSRodney W. Grimesto zero. 58058f0484fSRodney W. GrimesIf an error occurs, 58158f0484fSRodney W. Grimes.Fn fts_children 58258f0484fSRodney W. Grimesreturns 58358f0484fSRodney W. Grimes.Dv NULL 58458f0484fSRodney W. Grimesand sets 58558f0484fSRodney W. Grimes.Va errno 58658f0484fSRodney W. Grimesappropriately. 58758f0484fSRodney W. Grimes.Pp 58858f0484fSRodney W. GrimesThe 58958f0484fSRodney W. Grimes.Fa FTSENT 59058f0484fSRodney W. Grimesstructures returned by 59158f0484fSRodney W. Grimes.Fn fts_children 59258f0484fSRodney W. Grimesmay be overwritten after a call to 59358f0484fSRodney W. Grimes.Fn fts_children , 59458f0484fSRodney W. Grimes.Fn fts_close 59558f0484fSRodney W. Grimesor 59658f0484fSRodney W. Grimes.Fn fts_read 59758f0484fSRodney W. Grimeson the same file hierarchy stream. 59858f0484fSRodney W. Grimes.Pp 59958f0484fSRodney W. Grimes.Em Option 60058f0484fSRodney W. Grimesmay be set to the following value: 60158f0484fSRodney W. Grimes.Bl -tag -width FTS_NAMEONLY 60258f0484fSRodney W. Grimes.It Dv FTS_NAMEONLY 60358f0484fSRodney W. GrimesOnly the names of the files are needed. 60458f0484fSRodney W. GrimesThe contents of all the fields in the returned linked list of structures 60558f0484fSRodney W. Grimesare undefined with the exception of the 60658f0484fSRodney W. Grimes.Fa fts_name 60758f0484fSRodney W. Grimesand 60858f0484fSRodney W. Grimes.Fa fts_namelen 60958f0484fSRodney W. Grimesfields. 61058f0484fSRodney W. Grimes.El 61158f0484fSRodney W. Grimes.Sh FTS_SET 61258f0484fSRodney W. GrimesThe function 61358f0484fSRodney W. Grimes.Fn fts_set 61458f0484fSRodney W. Grimesallows the user application to determine further processing for the 61558f0484fSRodney W. Grimesfile 61658f0484fSRodney W. Grimes.Fa f 61758f0484fSRodney W. Grimesof the stream 61858f0484fSRodney W. Grimes.Fa ftsp . 61958f0484fSRodney W. GrimesThe 62058f0484fSRodney W. Grimes.Fn fts_set 62158f0484fSRodney W. Grimesfunction 62258f0484fSRodney W. Grimesreturns 0 on success, and \-1 if an error occurs. 62358f0484fSRodney W. Grimes.Em Option 62458f0484fSRodney W. Grimesmust be set to one of the following values: 62558f0484fSRodney W. Grimes.Bl -tag -width FTS_PHYSICAL 62658f0484fSRodney W. Grimes.It Dv FTS_AGAIN 62758f0484fSRodney W. GrimesRe-visit the file; any file type may be re-visited. 62858f0484fSRodney W. GrimesThe next call to 62958f0484fSRodney W. Grimes.Fn fts_read 63058f0484fSRodney W. Grimeswill return the referenced file. 63158f0484fSRodney W. GrimesThe 63258f0484fSRodney W. Grimes.Fa fts_stat 63358f0484fSRodney W. Grimesand 63458f0484fSRodney W. Grimes.Fa fts_info 63558f0484fSRodney W. Grimesfields of the structure will be reinitialized at that time, 63658f0484fSRodney W. Grimesbut no other fields will have been changed. 63758f0484fSRodney W. GrimesThis option is meaningful only for the most recently returned 63858f0484fSRodney W. Grimesfile from 63958f0484fSRodney W. Grimes.Fn fts_read . 64058f0484fSRodney W. GrimesNormal use is for post-order directory visits, where it causes the 64158f0484fSRodney W. Grimesdirectory to be re-visited (in both pre and post-order) as well as all 64258f0484fSRodney W. Grimesof its descendants. 64358f0484fSRodney W. Grimes.It Dv FTS_FOLLOW 64458f0484fSRodney W. GrimesThe referenced file must be a symbolic link. 64558f0484fSRodney W. GrimesIf the referenced file is the one most recently returned by 64658f0484fSRodney W. Grimes.Fn fts_read , 64758f0484fSRodney W. Grimesthe next call to 64858f0484fSRodney W. Grimes.Fn fts_read 64958f0484fSRodney W. Grimesreturns the file with the 65058f0484fSRodney W. Grimes.Fa fts_info 65158f0484fSRodney W. Grimesand 65258f0484fSRodney W. Grimes.Fa fts_statp 65358f0484fSRodney W. Grimesfields reinitialized to reflect the target of the symbolic link instead 65458f0484fSRodney W. Grimesof the symbolic link itself. 65558f0484fSRodney W. GrimesIf the file is one of those most recently returned by 65658f0484fSRodney W. Grimes.Fn fts_children , 65758f0484fSRodney W. Grimesthe 65858f0484fSRodney W. Grimes.Fa fts_info 65958f0484fSRodney W. Grimesand 66058f0484fSRodney W. Grimes.Fa fts_statp 66158f0484fSRodney W. Grimesfields of the structure, when returned by 66258f0484fSRodney W. Grimes.Fn fts_read , 66358f0484fSRodney W. Grimeswill reflect the target of the symbolic link instead of the symbolic link 66458f0484fSRodney W. Grimesitself. 66558f0484fSRodney W. GrimesIn either case, if the target of the symbolic link does not exist the 66658f0484fSRodney W. Grimesfields of the returned structure will be unchanged and the 66758f0484fSRodney W. Grimes.Fa fts_info 66858f0484fSRodney W. Grimesfield will be set to 66958f0484fSRodney W. Grimes.Dv FTS_SLNONE . 67058f0484fSRodney W. Grimes.Pp 67158f0484fSRodney W. GrimesIf the target of the link is a directory, the pre-order return, followed 67258f0484fSRodney W. Grimesby the return of all of its descendants, followed by a post-order return, 67358f0484fSRodney W. Grimesis done. 67458f0484fSRodney W. Grimes.It Dv FTS_SKIP 67558f0484fSRodney W. GrimesNo descendants of this file are visited. 67658f0484fSRodney W. GrimesThe file may be one of those most recently returned by either 67758f0484fSRodney W. Grimes.Fn fts_children 67858f0484fSRodney W. Grimesor 67958f0484fSRodney W. Grimes.Fn fts_read . 68058f0484fSRodney W. Grimes.El 68158f0484fSRodney W. Grimes.Sh FTS_CLOSE 68258f0484fSRodney W. GrimesThe 68358f0484fSRodney W. Grimes.Fn fts_close 68458f0484fSRodney W. Grimesfunction closes a file hierarchy stream 68558f0484fSRodney W. Grimes.Fa ftsp 68658f0484fSRodney W. Grimesand restores the current directory to the directory from which 68758f0484fSRodney W. Grimes.Fn fts_open 68858f0484fSRodney W. Grimeswas called to open 68958f0484fSRodney W. Grimes.Fa ftsp . 69058f0484fSRodney W. GrimesThe 69158f0484fSRodney W. Grimes.Fn fts_close 69258f0484fSRodney W. Grimesfunction 69358f0484fSRodney W. Grimesreturns 0 on success, and \-1 if an error occurs. 69458f0484fSRodney W. Grimes.Sh ERRORS 69558f0484fSRodney W. GrimesThe function 69658f0484fSRodney W. Grimes.Fn fts_open 69758f0484fSRodney W. Grimesmay fail and set 69858f0484fSRodney W. Grimes.Va errno 69958f0484fSRodney W. Grimesfor any of the errors specified for the library functions 70058f0484fSRodney W. Grimes.Xr open 2 70158f0484fSRodney W. Grimesand 70258f0484fSRodney W. Grimes.Xr malloc 3 . 70358f0484fSRodney W. Grimes.Pp 70458f0484fSRodney W. GrimesThe function 70558f0484fSRodney W. Grimes.Fn fts_close 70658f0484fSRodney W. Grimesmay fail and set 70758f0484fSRodney W. Grimes.Va errno 70858f0484fSRodney W. Grimesfor any of the errors specified for the library functions 70958f0484fSRodney W. Grimes.Xr chdir 2 71058f0484fSRodney W. Grimesand 71158f0484fSRodney W. Grimes.Xr close 2 . 71258f0484fSRodney W. Grimes.Pp 71358f0484fSRodney W. GrimesThe functions 71458f0484fSRodney W. Grimes.Fn fts_read 71558f0484fSRodney W. Grimesand 71658f0484fSRodney W. Grimes.Fn fts_children 71758f0484fSRodney W. Grimesmay fail and set 71858f0484fSRodney W. Grimes.Va errno 71958f0484fSRodney W. Grimesfor any of the errors specified for the library functions 72058f0484fSRodney W. Grimes.Xr chdir 2 , 72158f0484fSRodney W. Grimes.Xr malloc 3 , 72258f0484fSRodney W. Grimes.Xr opendir 3 , 72358f0484fSRodney W. Grimes.Xr readdir 3 72458f0484fSRodney W. Grimesand 72558f0484fSRodney W. Grimes.Xr stat 2 . 72658f0484fSRodney W. Grimes.Pp 72758f0484fSRodney W. GrimesIn addition, 72858f0484fSRodney W. Grimes.Fn fts_children , 72958f0484fSRodney W. Grimes.Fn fts_open 73058f0484fSRodney W. Grimesand 73158f0484fSRodney W. Grimes.Fn fts_set 73258f0484fSRodney W. Grimesmay fail and set 73358f0484fSRodney W. Grimes.Va errno 73458f0484fSRodney W. Grimesas follows: 73558f0484fSRodney W. Grimes.Bl -tag -width Er 73658f0484fSRodney W. Grimes.It Bq Er EINVAL 73758f0484fSRodney W. GrimesThe options were invalid. 73858f0484fSRodney W. Grimes.El 73958f0484fSRodney W. Grimes.Sh SEE ALSO 74058f0484fSRodney W. Grimes.Xr find 1 , 74158f0484fSRodney W. Grimes.Xr chdir 2 , 74258f0484fSRodney W. Grimes.Xr stat 2 , 74358f0484fSRodney W. Grimes.Xr qsort 3 74458f0484fSRodney W. Grimes.Sh STANDARDS 74558f0484fSRodney W. GrimesThe 74658f0484fSRodney W. Grimes.Nm fts 74758f0484fSRodney W. Grimesutility is expected to be included in a future 74858f0484fSRodney W. Grimes.St -p1003.1-88 74958f0484fSRodney W. Grimesrevision. 750