148352Scael.\" Copyright (c) 1989, 1991 The Regents of the University of California. 239801Sbostic.\" All rights reserved. 339801Sbostic.\" 443571Strent.\" %sccs.include.redist.man% 539801Sbostic.\" 6*52161Sbostic.\" @(#)fts.3 5.15 (Berkeley) 01/09/92 739801Sbostic.\" 848352Scael.Dd 948352Scael.Dt FTS 3 1048352Scael.Os 1148352Scael.Sh NAME 1248352Scael.Nm fts 1348352Scael.Nd traverse a file hierarchy 1448352Scael.Sh SYNOPSIS 1548352Scael.Fd #include <sys/types.h> 1648352Scael.Fd #include <sys/stat.h> 1748352Scael.Fd #include <fts.h> 1848352Scael.Ft FTS * 1948352Scael.Fn fts_open "char * const *path_argv" "int options" "int *compar(const FTSENT *, const FTSENT *)" 2048352Scael.Ft FTSENT * 2148352Scael.Fn fts_read "FTS *ftsp" 2248352Scael.Ft FTSENT * 2348352Scael.Fn fts_children "FTS *ftsp" 2448352Scael.Ft int 2548352Scael.Fn fts_set "FTS ftsp" "FTSENT *f" "int options" 2648352Scael.Ft int 2748352Scael.Fn fts_close "FTS *ftsp" 2848352Scael.Sh DESCRIPTION 2939801SbosticThe 3048352Scael.Nm fts 3148352Scaelfunctions are provided for traversing 3248352Scael.Tn UNIX 3348352Scaelfile hierarchies. 3448352Scael.Pp 3547194SbosticThe simple overview is that the 3648352Scael.Fn fts_open 3747194Sbosticfunction returns a ``handle'' on a file hierarchy, which is supplied to 3847194Sbosticthe other 3948352Scael.Nm fts 4045617Sbosticfunctions to determine which hierarchy they operate on. 4145617SbosticThe function 4248352Scael.Fn fts_read 4345617Sbosticreturns a pointer to a structure describing one of the files in the file 4445617Sbostichierarchy. 4545617SbosticThe function 4648352Scael.Fn fts_children 4745617Sbosticreturns a pointer to a linked list of structures, each of which describes 4845617Sbosticone of the files contained in a directory in the hierarchy. 4945617SbosticIn general, directories are visited two distinguishable times; in pre-order 5045617Sbostic(before any of their descendants are visited) and in post-order (after all 5145617Sbosticof their descendants have been visited). 5245617SbosticFiles are visited once. 5345617SbosticIt is possible to walk the hierarchy ``logically'' (ignoring symbolic links) 5445617Sbosticor physically (visiting symbolic links), order the walk of the hierarchy or 5545617Sbosticprune and/or re-visit portions of the hierarchy. 5648352Scael.Pp 5748352ScaelTwo structures are defined (and typedef'd) in the include file 5848352Scael.Aq Pa fts.h . 5948352ScaelThe first is 6048352Scael.Fa FTS , 6148352Scaelthe structure that represents the file hierarchy stream. 6248352ScaelThe second is 6348352Scael.Fa FTSENT , 6448352Scaelthe structure that represents a file in the file 6545617Sbostichierarchy. 6648352ScaelNormally, an 6748352Scael.Fa FTSENT 6848352Scaelstructure is returned for every file in the file 6945617Sbostichierarchy. 7048352ScaelIn this manual page, ``file'' and 7148352Scael.Dq Fa FTSENT No structure 7248352Scaelare generally 7345617Sbosticinterchangeable. 7448352ScaelThe 7548352Scael.Fa FTSENT 7648352Scaelstructure contains at least the following fields, which are 7745617Sbosticdescribed in greater detail below: 7850725Scael.Bd -literal 7945617Sbostictypedef struct _ftsent { 8048352Scael u_short fts_info; /* flags for FTSENT structure */ 8148352Scael char *fts_accpath; /* access path */ 8245617Sbostic char *fts_path; /* root path */ 8348352Scael short fts_pathlen; /* strlen(fts_path) */ 8442273Sbostic char *fts_name; /* file name */ 8548352Scael short fts_namelen; /* strlen(fts_name) */ 8648352Scael short fts_level; /* depth (\-1 to N) */ 87*52161Sbostic int fts_error; /* node errno */ 8848352Scael long fts_number; /* local numeric value */ 8945617Sbostic void *fts_pointer; /* local address value */ 9048352Scael struct ftsent *fts_parent; /* parent directory */ 9152075Sbostic struct ftsent *fts_link; /* next file structure */ 9252075Sbostic struct ftsent *fts_cycle; /* cycle structure */ 9348352Scael struct stat fts_statb; /* stat(2) information */ 9439801Sbostic} FTSENT; 9548352Scael.Ed 9648352Scael.Pp 9745617SbosticThese fields are defined as follows: 9848352Scael.Bl -tag -width "fts_namelen" 9948352Scael.It Fa fts_info 10048352ScaelOne of the following flags describing the returned 10148352Scael.Fa FTSENT 10248352Scaelstructure and 10345617Sbosticthe file it represents. 10448352ScaelWith the exception of directories without errors 10548352Scael.Pq Dv FTS_D , 10648352Scaelall of these 10745617Sbosticentries are terminal, that is, they will not be revisited, nor will any 10845617Sbosticof their descendants be visited. 10948352Scael.Bl -tag -width FTS_DEFAULT 11048352Scael.It Dv FTS_D 11139801SbosticA directory being visited in pre-order. 11248352Scael.It Dv FTS_DC 11345617SbosticA directory that causes a cycle in the tree. 11445617Sbostic(The 11552075Sbostic.Fa fts_cycle 11648352Scaelfield of the 11748352Scael.Fa FTSENT 11848352Scaelstructure will be filled in as well.) 11948352Scael.It Dv FTS_DEFAULT 12048352ScaelAny 12148352Scael.Fa FTSENT 12248352Scaelstructure that represents a file type not explicitly described 12345617Sbosticby one of the other 12448352Scael.Fa fts_info 12545617Sbosticvalues. 12648352Scael.It Dv FTS_DNR 12745617SbosticA directory which cannot be read. 128*52161SbosticThis is an error return, and the 129*52161Sbostic.Fa fts_errno 130*52161Sbosticfield will be set to indicate what caused the error. 13148352Scael.It Dv FTS_DP 13245617SbosticA directory being visited in post-order. 13348352ScaelThe contents of the 13448352Scael.Fa FTSENT 13548352Scaelstructure will be unchanged from when 13645617Sbosticit was returned in pre-order, i.e. with the 13748352Scael.Fa fts_info 13848352Scaelfield set to 13948352Scael.Dv FTS_D . 14048352Scael.It Dv FTS_ERR 141*52161SbosticThis is an error return, and the 142*52161Sbostic.Fa fts_errno 143*52161Sbosticfield will be set to indicate what caused the error. 14448352Scael.It Dv FTS_F 14539801SbosticA regular file. 14648352Scael.It Dv FTS_NS 14745617SbosticA file for which no 14848352Scael.Xr stat 2 14947194Sbosticinformation was available. 15047194SbosticThe contents of the 15148352Scael.Fa fts_statb 15239801Sbosticfield are undefined. 153*52161SbosticThis is an error return, and the 154*52161Sbostic.Fa fts_errno 155*52161Sbosticfield will be set to indicate what caused the error. 15648352Scael.It Dv FTS_NSOK 15747194SbosticA file for which no 15848352Scael.Xr stat 2 15947194Sbosticinformation was requested. 16047194SbosticThe contents of the 16148352Scael.Fa fts_statb 16247194Sbosticfield are undefined. 16348352Scael.It Dv FTS_SL 16439801SbosticA symbolic link. 16548352Scael.It Dv FTS_SLNONE 16639801SbosticA symbolic link with a non-existent target. 16747194SbosticThe contents of the 16848352Scael.Fa fts_statb 16947194Sbosticfield contain the file characteristic information for the symbolic link 17047194Sbosticitself. 17148352Scael.El 17248352Scael.It Fa fts_accpath 17347194SbosticA path for accessing the file from the current directory. 17448352Scael.It Fa fts_path 17545617SbosticThe path for the file relative to the root of the traversal. 17645617SbosticThis path contains the path specified to 17748352Scael.Fn fts_open 17845617Sbosticas a prefix. 17948352Scael.It Fa fts_pathlen 18045617SbosticThe length of the string referenced by 18148352Scael.Fa fts_path . 18248352Scael.It Fa fts_name 18345617SbosticThe name of the file. 18448352Scael.It Fa fts_namelen 18545617SbosticThe length of the string referenced by 18648352Scael.Fa fts_name . 18748352Scael.It Fa fts_level 18845617SbosticThe depth of the traversal, numbered from \-1 to N, where this file 18945617Sbosticwas found. 19048352ScaelThe 19148352Scael.Fa FTSENT 19248352Scaelstructure representing the parent of the starting point (or root) 19348352Scaelof the traversal is numbered \-1, and the 19448352Scael.Fa FTSENT 19548352Scaelstructure for the root 19645617Sbosticitself is numbered 0. 197*52161Sbostic.It Fa fts_errno 198*52161SbosticUpon return of a node from the 199*52161Sbostic.Fn fts_children 200*52161Sbosticor 201*52161Sbostic.Fn fts_read 202*52161Sbosticfunctions, with its 203*52161Sbostic.Fa fts_info 204*52161Sbosticfield set to 205*52161Sbostic.Dv FTS_ERR 206*52161Sbosticor 207*52161Sbostic.Dv FTS_NS , 208*52161Sbosticthe 209*52161Sbostic.Fa fts_errno 210*52161Sbosticfield contains the value of the external variable 211*52161Sbostic.Va errno 212*52161Sbosticspecifying the cause of the error. 213*52161SbosticOtherwise, the contents of the 214*52161Sbostic.Fa fts_errno 215*52161Sbosticfield are undefined. 21648352Scael.It Fa fts_number 21745617SbosticThis field is provided for the use of the application program and is 21845617Sbosticnot modified by the 21948352Scael.Nm fts 22045617Sbosticfunctions. 22145617SbosticIt is initialized to 0. 22245617SbosticThe fields 22348352Scael.Fa fts_number 22445617Sbosticand 22548352Scael.Fa fts_pointer 22645617Sbosticoccupy the same physical location; using both may cause undefined results. 22748352Scael.It Fa fts_pointer 22845617SbosticThis field is provided for the use of the application program and is 22945617Sbosticnot modified by the 23048352Scael.Nm fts 23145617Sbosticfunctions. 23248352ScaelIt is initialized to 23348352Scael.Dv NULL . 23445617SbosticThe fields 23548352Scael.Fa fts_number 23645617Sbosticand 23748352Scael.Fa fts_pointer 23845617Sbosticoccupy the same physical location; using both may cause undefined results. 23948352Scael.It Fa fts_parent 24048352ScaelA pointer to the 24148352Scael.Fa FTSENT 24248352Scaelstructure referencing the file in the hierarchy 24345617Sbosticimmediately above the current file, i.e. the directory of which this 24445617Sbosticfile is a member. 24545617SbosticA parent structure for the initial entry point is provided as well, 24645617Sbostichowever, only the 24748352Scael.Fa fts_level , 24848352Scael.Fa fts_number 24945617Sbosticand 25048352Scael.Fa fts_pointer 25145617Sbosticfields are guaranteed to be initialized. 25248352Scael.It Fa fts_link 25352075SbosticUpon return from the 25452075Sbostic.Fn fts_children 25552075Sbosticfunction, the 25648352Scael.Fa fts_link 25752075Sbosticfield points to the next structure in the NULL-terminated linked list of 25852075Sbosticdirectory members. 25952075SbosticOtherwise, the contents of the 26052075Sbostic.Fa fts_link 26152075Sbosticfield are undefined. 26252075Sbostic.It Fa fts_cycle 26348352ScaelIf a directory causes a cycle in the hierarchy (see 26448352Scael.Dv FTS_DC ) , 26548352Scaeleither because 26645617Sbosticof a hard link between two directories, or a symbolic link pointing to a 26745617Sbosticdirectory, the 26852075Sbostic.Fa fts_cycle 26948352Scaelfield of the structure will point to the 27048352Scael.Fa FTSENT 27152075Sbosticstructure in the hierarchy that references the same file as the current 27248352Scael.Fa FTSENT 27348352Scaelstructure. 27445617SbosticOtherwise, the contents of the 27552075Sbostic.Fa fts_cycle 27645617Sbosticfield are undefined. 27748352Scael.It Fa fts_statb 27848352Scael.Xr Stat 2 27939801Sbosticinformation for the file. 28048352Scael.El 281*52161Sbostic.Pp 282*52161SbosticA single buffer is used for all of the paths of all of the files in the 283*52161Sbosticfile hierarchy. 284*52161SbosticTherefore, the 285*52161Sbostic.Fa fts_path 286*52161Sbosticand 287*52161Sbostic.Fa fts_accpath 288*52161Sbosticfields are guaranteed to be 289*52161Sbostic.Dv NULL Ns -terminated 290*52161Sbostic.Em only 291*52161Sbosticfor the file most recently returned by 292*52161Sbostic.Fn fts_read . 293*52161SbosticTo use these fields to reference any files represented by other 294*52161Sbostic.Fa FTSENT 295*52161Sbosticstructures will require that the path buffer be modified using the 296*52161Sbosticinformation contained in that 297*52161Sbostic.Fa FTSENT 298*52161Sbosticstructure's 299*52161Sbostic.Fa fts_pathlen 300*52161Sbosticfield. 301*52161SbosticAny such modifications should be undone before further calls to 302*52161Sbostic.Fn fts_read 303*52161Sbosticare attempted. 304*52161SbosticThe 305*52161Sbostic.Fa fts_name 306*52161Sbosticfield is always 307*52161Sbostic.Dv NULL Ns -terminated. 30848352Scael.Sh FTS_OPEN 30945617SbosticThe 31048352Scael.Fn fts_open 31145617Sbosticfunction takes a pointer to an array of character pointers naming one 31245617Sbosticor more paths which make up a logical file hierarchy to be traversed. 31348352ScaelThe array must be terminated by a 31448352Scael.Dv NULL 31548352Scaelpointer. 31648352Scael.Pp 31748352ScaelThere are 31848352Scaela number of options, at least one of which (either 31948352Scael.Dv FTS_LOGICAL 32048352Scaelor 32148352Scael.Dv FTS_PHYSICAL ) 32248352Scaelmust be specified. 32345617SbosticThe options are selected by 32448352Scael.Em or Ns 'ing 32545617Sbosticthe following values: 32648352Scael.Bl -tag -width "FTS_PHYSICAL" 32748352Scael.It Dv FTS_LOGICAL 32845617SbosticThis option causes the 32948352Scael.Nm fts 33048352Scaelroutines to return 33148352Scael.Fa FTSENT 33248352Scaelstructures for the targets of symbolic links 33345617Sbosticinstead of the symbolic links themselves. 33448352ScaelIf this option is set, the only symbolic links for which 33548352Scael.Fa FTSENT 33648352Scaelstructures 33745617Sbosticare returned to the application are those referencing non-existent files. 33848352ScaelEither 33948352Scael.Dv FTS_LOGICAL 34048352Scaelor 34148352Scael.Dv FTS_PHYSICAL 34248352Scael.Em must 34345617Sbosticbe provided to the 34448352Scael.Fn fts_open 34545617Sbosticfunction. 34648352Scael.It Dv FTS_NOCHDIR 34745617SbosticAs a performance optimization, the 34848352Scael.Nm fts 34945617Sbosticfunctions change directories as they walk the file hierarchy. 35045617SbosticThis has the side-effect that an application cannot rely on being 35145617Sbosticin any particular directory during the traversal. 35248352ScaelThe 35348352Scael.Dv FTS_NOCHDIR 35448352Scaeloption turns off this optimization, and the 35548352Scael.Nm fts 35645617Sbosticfunctions will not change the current directory. 35745617SbosticNote that applications should not themselves change their current directory 35848352Scaeland try to access files unless 35948352Scael.Dv FTS_NOCHDIR 36048352Scaelis specified and absolute 36145617Sbosticpathnames were provided as arguments to 36248352Scael.Fn fts_open . 36348352Scael.It Dv FTS_NOSTAT 36448352ScaelBy default, returned 36548352Scael.Fa FTSENT 36648352Scaelstructures contain file characteristic 36745617Sbosticinformation (the 36848352Scael.Fa statb 36945617Sbosticfield) for each file visited. 37045617SbosticThis option relaxes that requirement as a performance optimization, 37145617Sbosticallowing the 37248352Scael.Nm fts 37345617Sbosticfunctions to set the 37448352Scael.Fa fts_info 37548352Scaelfield to 37648352Scael.Dv FTS_NSOK 37748352Scaeland leave the contents of the 37848352Scael.Fa statb 37945617Sbosticfield undefined. 38048352Scael.It Dv FTS_PHYSICAL 38145617SbosticThis option causes the 38248352Scael.Nm fts 38348352Scaelroutines to return 38448352Scael.Fa FTSENT 38548352Scaelstructures for symbolic links themselves instead 38645617Sbosticof the target files they point to. 38748352ScaelIf this option is set, 38848352Scael.Fa FTSENT 38948352Scaelstructures for all symbolic links in the 39045617Sbostichierarchy are returned to the application. 39148352ScaelEither 39248352Scael.Dv FTS_LOGICAL 39348352Scaelor 39448352Scael.Dv FTS_PHYSICAL 39548352Scael.Em must 39645617Sbosticbe provided to the 39748352Scael.Fn fts_open 39845617Sbosticfunction. 39948352Scael.It Dv FTS_SEEDOT 40045617SbosticBy default, unless they are specified as path arguments to 40148352Scael.Fn fts_open , 40248352Scaelany files named 40348352Scael.Ql \&. 40452067Sbosticor 40548352Scael.Ql .. 40648352Scaelencountered in the file hierarchy are 40745617Sbosticignored. 40845617SbosticThis option causes the 40948352Scael.Nm fts 41048352Scaelroutines to return 41148352Scael.Fa FTSENT 41248352Scaelstructures for them. 41348352Scael.It Dv FTS_XDEV 41445617SbosticThis option prevents 41548352Scael.Nm fts 41645617Sbosticfrom descending into directories that have a different device number 41745617Sbosticthan the file from which the descent began. 41848352Scael.El 41948352Scael.Pp 42045617SbosticThe argument 42148352Scael.Fn compar 42245617Sbosticspecifies a user-defined function which may be used to order the traversal 42345617Sbosticof the hierarchy. 42448352ScaelIt 42548352Scaeltakes two pointers to pointers to 42648352Scael.Fa FTSENT 42748352Scaelstructures as arguments and 42845617Sbosticshould return a negative value, zero, or a positive value to indicate 42945617Sbosticif the file referenced by its first argument comes before, in any order 43045617Sbosticwith respect to, or after, the file referenced by its second argument. 43139801SbosticThe 43248352Scael.Fa fts_accpath , 43348352Scael.Fa fts_path 43439801Sbosticand 43548352Scael.Fa fts_pathlen 43648352Scaelfields of the 43748352Scael.Fa FTSENT 43848352Scaelstructures may 43948352Scael.Em never 44045617Sbosticbe used in this comparison. 44147194SbosticIf the 44248352Scael.Fa fts_info 44348352Scaelfield is set to 44448352Scael.Dv FTS_NS 44548352Scaelor 44648352Scael.DV FTS_NSOK , 44748352Scaelthe 44848352Scael.Fa fts_stab 44945617Sbosticfield may not either. 45045617SbosticIf the 45148352Scael.Fn compar 45248352Scaelargument is 45348352Scael.Dv NULL , 45448352Scaelthe directory traversal order is unspecified except 45545617Sbosticfor the root paths which are traversed in the order listed in 45648352Scael.Fa path_argv . 45748352Scael.Sh FTS_READ 45839801SbosticThe 45948352Scael.Fn fts_read 46048352Scaelfunction returns a pointer to an 46148352Scael.Fa FTSENT 46248352Scaelstructure describing a file in 46345617Sbosticthe hierarchy. 46447194SbosticDirectories (that are readable and do not cause cycles) are visited at 46547194Sbosticleast twice, once in pre-order and once in post-order. 46645617SbosticAll other files are visited at least once. 46745617Sbostic(Hard links between directories that do not cause cycles or symbolic 46845617Sbosticlinks to symbolic links may cause files to be visited more than once, 46945617Sbosticor directories more than twice.) 47048352Scael.Pp 47139801SbosticIf all the members of the hierarchy have been returned, 47248352Scael.Fn fts_read 47348352Scaelreturns 47448352Scael.Dv NULL 47548352Scaeland sets the external variable 47648352Scael.Va errno 47739801Sbosticto 0. 47839801SbosticIf an error unrelated to a file in the hierarchy occurs, 47948352Scael.Fn fts_read 48048352Scaelreturns 48148352Scael.Dv NULL 48248352Scaeland sets 48348352Scael.Va errno 48445617Sbosticappropriately. 48548352ScaelIf an error related to a returned file occurs, a pointer to an 48648352Scael.Fa FTSENT 48745617Sbosticstructure is returned, and 48848352Scael.Va errno 48945617Sbosticmay or may not have been set (see 49048352Scael.Fa fts_info ) . 49148352Scael.Pp 49248352ScaelThe 49348352Scael.Fa FTSENT 49448352Scaelstructures returned by 49548352Scael.Fn fts_read 49645617Sbosticmay be overwritten after a call to 49748352Scael.Fn fts_close 49845617Sbosticon the same file hierarchy stream, or, after a call to 49948352Scael.Fn fts_read 50045617Sbosticon the same file hierarchy stream unless they represent a file of type 50145617Sbosticdirectory, in which case they will not be overwritten until after a call to 50248352Scael.Fn fts_read 50348352Scaelafter the 50448352Scael.Fa FTSENT 50548352Scaelstructure has been returned by the function 50648352Scael.Fn fts_read 50745617Sbosticin post-order. 50848352Scael.Sh FTS_CHILDREN 50945617SbosticThe 51048352Scael.Fn fts_children 51148352Scaelfunction returns a pointer to an 51248352Scael.Fa FTSENT 513*52161Sbosticstructure describing the first entry in a NULL-terminated linked list of 514*52161Sbosticthe files in the directory represented by the 51548352Scael.Fa FTSENT 51648352Scaelstructure most recently returned by 51748352Scael.Fn fts_read . 51845617SbosticThe list is linked through the 51948352Scael.Fa fts_link 52048352Scaelfield of the 52148352Scael.Fa FTSENT 522*52161Sbosticstructure, and is ordered by the user-specified comparison function, if any. 52345617SbosticRepeated calls to 52448352Scael.Fn fts_children 52545617Sbosticwill recreate this linked list. 52648352Scael.Pp 527*52161SbosticAs a special case, if 528*52161Sbostic.Fn fts_read 529*52161Sbostichas not yet been called for a hierarchy, 530*52161Sbostic.Fn fts_children 531*52161Sbosticwill return a pointer to the files in the logical directory specified to 532*52161Sbostic.Fn fts_open , 533*52161Sbostici.e. the arguments specified to 534*52161Sbostic.Fn fts_open . 535*52161SbosticOtherwise, if the 53648352Scael.Fa FTSENT 53748352Scaelstructure most recently returned by 53848352Scael.Fn fts_read 53945617Sbosticis not a directory being visited in pre-order, 54045617Sbosticor the directory does not contain any files, 54148352Scael.Fn fts_children 54248352Scaelreturns 54348352Scael.Dv NULL 54448352Scaeland sets 54548352Scael.Va errno 54645617Sbosticto zero. 54739801SbosticIf an error occurs, 54848352Scael.Fn fts_children 54948352Scaelreturns 55048352Scael.Dv NULL 55148352Scaeland sets 55248352Scael.Va errno 55345617Sbosticappropriately. 55448352Scael.Pp 55548352ScaelThe 55648352Scael.Fa FTSENT 55748352Scaelstructures returned by 55848352Scael.Fn fts_children 55939801Sbosticmay be overwritten after a call to 56052075Sbostic.Fn fts_children , 56148352Scael.Fn fts_close 56239801Sbosticor 56348352Scael.Fn fts_read 56445617Sbosticon the same file hierarchy stream. 56548352Scael.Sh FTS_SET 56645617SbosticThe function 56748352Scael.Fn fts_set 56839801Sbosticallows the user application to determine further processing for the 56939801Sbosticfile 57048352Scael.Fa f 57139801Sbosticof the stream 57248352Scael.Fa ftsp . 57348352ScaelThe 57448352Scael.Fn fts_set 57548352Scaelfunction 57648352Scaelreturns 0 on success, and \-1 if an error occurs. 57748352Scael.Em Option 57845617Sbosticmust be set to one of the following values: 57948352Scael.Bl -tag -width FTS_PHYSICAL 58048352Scael.It Dv FTS_AGAIN 58139801SbosticRe-visit the file; any file type may be re-visited. 58239801SbosticThe next call to 58348352Scael.Fn fts_read 58439801Sbosticwill return the referenced file. 58545617SbosticThe 58648352Scael.Fa fts_stat 58739801Sbosticand 58848352Scael.Fa fts_info 58939801Sbosticfields of the structure will be reinitialized at that time, 59045617Sbosticbut no other fields will have been changed. 59139801SbosticThis option is meaningful only for the most recently returned 59239801Sbosticfile from 59348352Scael.Fn fts_read . 59439801SbosticNormal use is for post-order directory visits, where it causes the 59539801Sbosticdirectory to be re-visited (in both pre and post-order) as well as all 59639801Sbosticof its descendants. 59748352Scael.It Dv FTS_FOLLOW 59839801SbosticThe referenced file must be a symbolic link. 59939801SbosticIf the referenced file is the one most recently returned by 60048352Scael.Fn fts_read , 60139801Sbosticthe next call to 60248352Scael.Fn fts_read 60339801Sbosticreturns the file with the 60448352Scael.Fa fts_info 60539801Sbosticand 60648352Scael.Fa fts_statb 60739801Sbosticfields reinitialized to reflect the target of the symbolic link instead 60839801Sbosticof the symbolic link itself. 60939801SbosticIf the file is one of those most recently returned by 61048352Scael.Fn fts_children , 61139801Sbosticthe 61248352Scael.Fa fts_info 61339801Sbosticand 61448352Scael.Fa fts_statb 61539801Sbosticfields of the structure, when returned by 61648352Scael.Fn fts_read , 61739801Sbosticwill reflect the target of the symbolic link instead of the symbolic link 61839801Sbosticitself. 61947194SbosticIn either case, if the target of the symbolic link does not exist the 62047194Sbosticfields of the returned structure will be unchanged and the 62148352Scael.Fa fts_info 62248352Scaelfield will be set to 62348352Scael.Dv FTS_SLNONE . 62448352Scael.Pp 62547194SbosticIf the target of the link is a directory, the pre-order return, followed 62647194Sbosticby the return of all of its descendants, followed by a post-order return, 62747194Sbosticis done. 62848352Scael.It Dv FTS_SKIP 62939801SbosticNo descendants of this file are visited. 63045617SbosticThe file may be one of those most recently returned by either 63148352Scael.Fn fts_children 63245617Sbosticor 63348352Scael.Fn fts_read . 63448352Scael.El 63548352Scael.Sh FTS_CLOSE 63645617SbosticThe 63748352Scael.Fn fts_close 63845617Sbosticfunction closes a file hierarchy stream 63948352Scael.Fa ftsp 64045617Sbosticand restores the current directory to the directory from which 64148352Scael.Fn fts_open 64245617Sbosticwas called to open 64348352Scael.Fa ftsp . 64448352ScaelThe 64548352Scael.Fn fts_close 64648352Scaelfunction 64748352Scaelreturns 0 on success, and \-1 if an error occurs. 64848352Scael.Sh ERRORS 64948352ScaelThe function 65048352Scael.Fn fts_open 65139801Sbosticmay fail and set errno for any of the errors specified for the library 65245661Sbosticfunctions 65348352Scael.Xr open 2 65445661Sbosticand 65548352Scael.Xr malloc 3 . 65648352Scael.Pp 65748352ScaelThe function 65848352Scael.Fn fts_close 65939801Sbosticmay fail and set errno for any of the errors specified for the library 66045661Sbosticfunctions 66148352Scael.Xr chdir 2 66245661Sbosticand 66348352Scael.Xr close 2 . 66448352Scael.Pp 66548352ScaelThe functions 66650943Sbostic.Fn fts_read 66739801Sbosticand 66848352Scael.Fn fts_children 66939801Sbosticmay fail and set errno for any of the errors specified for the library 67045617Sbosticfunctions 67148352Scael.Xr chdir 2 , 67248352Scael.Xr malloc 3 , 67348352Scael.Xr opendir 3 , 67448352Scael.Xr readdir 3 67539801Sbosticand 67648352Scael.Xr stat 2 . 67748352Scael.Sh SEE ALSO 67848352Scael.Xr find 1 , 67948352Scael.Xr chdir 2 , 68048352Scael.Xr stat 2 , 68148352Scael.Xr qsort 3 68248352Scael.Sh STANDARDS 68339801SbosticThe 68448352Scael.Nm fts 68548352Scaelutility is expected to be a superset of the 68648352Scael.St -p1003.1-88 68747194Sbosticspecification. 688