148352Scael.\" Copyright (c) 1989, 1991 The Regents of the University of California. 239801Sbostic.\" All rights reserved. 339801Sbostic.\" 443571Strent.\" %sccs.include.redist.man% 539801Sbostic.\" 6*52769Sbostic.\" @(#)fts.3 5.20 (Berkeley) 03/01/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 * 1952228Selan.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 * 23*52769Sbostic.Fn fts_children "FTS *ftsp" "int options" 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. 3452208SbosticA simple overview is that the 3548352Scael.Fn fts_open 3652208Sbosticfunction returns a ``handle'' on a file hierarchy, which is then supplied to 3747194Sbosticthe other 3848352Scael.Nm fts 3952208Sbosticfunctions. 4045617SbosticThe function 4148352Scael.Fn fts_read 4245617Sbosticreturns a pointer to a structure describing one of the files in the file 4345617Sbostichierarchy. 4445617SbosticThe function 4548352Scael.Fn fts_children 4645617Sbosticreturns a pointer to a linked list of structures, each of which describes 4745617Sbosticone of the files contained in a directory in the hierarchy. 4845617SbosticIn general, directories are visited two distinguishable times; in pre-order 4945617Sbostic(before any of their descendants are visited) and in post-order (after all 5045617Sbosticof their descendants have been visited). 5145617SbosticFiles are visited once. 5245617SbosticIt is possible to walk the hierarchy ``logically'' (ignoring symbolic links) 5345617Sbosticor physically (visiting symbolic links), order the walk of the hierarchy or 5445617Sbosticprune and/or re-visit portions of the hierarchy. 5548352Scael.Pp 5648352ScaelTwo structures are defined (and typedef'd) in the include file 5748352Scael.Aq Pa fts.h . 5848352ScaelThe first is 5948352Scael.Fa FTS , 6052208Sbosticthe structure that represents the file hierarchy itself. 6148352ScaelThe second is 6248352Scael.Fa FTSENT , 6348352Scaelthe structure that represents a file in the file 6445617Sbostichierarchy. 6548352ScaelNormally, an 6648352Scael.Fa FTSENT 6748352Scaelstructure is returned for every file in the file 6845617Sbostichierarchy. 6948352ScaelIn this manual page, ``file'' and 7048352Scael.Dq Fa FTSENT No structure 7148352Scaelare generally 7245617Sbosticinterchangeable. 7348352ScaelThe 7448352Scael.Fa FTSENT 7548352Scaelstructure contains at least the following fields, which are 7645617Sbosticdescribed in greater detail below: 7750725Scael.Bd -literal 7845617Sbostictypedef struct _ftsent { 7948352Scael u_short fts_info; /* flags for FTSENT structure */ 8048352Scael char *fts_accpath; /* access path */ 8145617Sbostic char *fts_path; /* root path */ 8248352Scael short fts_pathlen; /* strlen(fts_path) */ 8342273Sbostic char *fts_name; /* file name */ 8448352Scael short fts_namelen; /* strlen(fts_name) */ 8548352Scael short fts_level; /* depth (\-1 to N) */ 8652208Sbostic int fts_error; /* file errno */ 8748352Scael long fts_number; /* local numeric value */ 8845617Sbostic void *fts_pointer; /* local address value */ 8948352Scael struct ftsent *fts_parent; /* parent directory */ 9052075Sbostic struct ftsent *fts_link; /* next file structure */ 9152075Sbostic struct ftsent *fts_cycle; /* cycle structure */ 9252227Sbostic struct stat *fts_statp; /* stat(2) information */ 9339801Sbostic} FTSENT; 9448352Scael.Ed 9548352Scael.Pp 9645617SbosticThese fields are defined as follows: 9748352Scael.Bl -tag -width "fts_namelen" 9848352Scael.It Fa fts_info 9948352ScaelOne of the following flags describing the returned 10048352Scael.Fa FTSENT 10148352Scaelstructure and 10245617Sbosticthe file it represents. 10348352ScaelWith the exception of directories without errors 10448352Scael.Pq Dv FTS_D , 10548352Scaelall of these 10645617Sbosticentries are terminal, that is, they will not be revisited, nor will any 10745617Sbosticof their descendants be visited. 10848352Scael.Bl -tag -width FTS_DEFAULT 10948352Scael.It Dv FTS_D 11039801SbosticA directory being visited in pre-order. 11148352Scael.It Dv FTS_DC 11245617SbosticA directory that causes a cycle in the tree. 11345617Sbostic(The 11452075Sbostic.Fa fts_cycle 11548352Scaelfield of the 11648352Scael.Fa FTSENT 11748352Scaelstructure will be filled in as well.) 11848352Scael.It Dv FTS_DEFAULT 11948352ScaelAny 12048352Scael.Fa FTSENT 12148352Scaelstructure that represents a file type not explicitly described 12245617Sbosticby one of the other 12348352Scael.Fa fts_info 12445617Sbosticvalues. 12548352Scael.It Dv FTS_DNR 12645617SbosticA directory which cannot be read. 12752161SbosticThis is an error return, and the 12852161Sbostic.Fa fts_errno 12952161Sbosticfield will be set to indicate what caused the error. 13052208Sbostic.It Dv FTS_DOT 13152208SbosticA file named 13252208Sbostic.Ql \&. 13352208Sbosticor 13452208Sbostic.Ql .. 13552208Sbosticwhich was not specified as a file name to 13652208Sbostic.Fn fts_open 13752208Sbostic(see 13852208Sbostic.Dv FTS_SEEDOT ) . 13948352Scael.It Dv FTS_DP 14045617SbosticA directory being visited in post-order. 14148352ScaelThe contents of the 14248352Scael.Fa FTSENT 14348352Scaelstructure will be unchanged from when 14445617Sbosticit was returned in pre-order, i.e. with the 14548352Scael.Fa fts_info 14648352Scaelfield set to 14748352Scael.Dv FTS_D . 14848352Scael.It Dv FTS_ERR 14952161SbosticThis is an error return, and the 15052161Sbostic.Fa fts_errno 15152161Sbosticfield will be set to indicate what caused the error. 15248352Scael.It Dv FTS_F 15339801SbosticA regular file. 15448352Scael.It Dv FTS_NS 15545617SbosticA file for which no 15648352Scael.Xr stat 2 15747194Sbosticinformation was available. 15847194SbosticThe contents of the 15952227Sbostic.Fa fts_statp 16039801Sbosticfield are undefined. 16152161SbosticThis is an error return, and the 16252161Sbostic.Fa fts_errno 16352161Sbosticfield will be set to indicate what caused the error. 16448352Scael.It Dv FTS_NSOK 16547194SbosticA file for which no 16648352Scael.Xr stat 2 16747194Sbosticinformation was requested. 16847194SbosticThe contents of the 16952227Sbostic.Fa fts_statp 17047194Sbosticfield are undefined. 17148352Scael.It Dv FTS_SL 17239801SbosticA symbolic link. 17348352Scael.It Dv FTS_SLNONE 17439801SbosticA symbolic link with a non-existent target. 17547194SbosticThe contents of the 17652227Sbostic.Fa fts_statp 17752227Sbosticfield reference the file characteristic information for the symbolic link 17847194Sbosticitself. 17948352Scael.El 18048352Scael.It Fa fts_accpath 18147194SbosticA path for accessing the file from the current directory. 18248352Scael.It Fa fts_path 18345617SbosticThe path for the file relative to the root of the traversal. 18445617SbosticThis path contains the path specified to 18548352Scael.Fn fts_open 18645617Sbosticas a prefix. 18748352Scael.It Fa fts_pathlen 18845617SbosticThe length of the string referenced by 18948352Scael.Fa fts_path . 19048352Scael.It Fa fts_name 19145617SbosticThe name of the file. 19248352Scael.It Fa fts_namelen 19345617SbosticThe length of the string referenced by 19448352Scael.Fa fts_name . 19548352Scael.It Fa fts_level 19645617SbosticThe depth of the traversal, numbered from \-1 to N, where this file 19745617Sbosticwas found. 19848352ScaelThe 19948352Scael.Fa FTSENT 20048352Scaelstructure representing the parent of the starting point (or root) 20148352Scaelof the traversal is numbered \-1, and the 20248352Scael.Fa FTSENT 20348352Scaelstructure for the root 20445617Sbosticitself is numbered 0. 20552161Sbostic.It Fa fts_errno 20652208SbosticUpon return of a 20752208Sbostic.Fa FTSENT 20852208Sbosticstructure from the 20952161Sbostic.Fn fts_children 21052161Sbosticor 21152161Sbostic.Fn fts_read 21252161Sbosticfunctions, with its 21352161Sbostic.Fa fts_info 21452161Sbosticfield set to 21552208Sbostic.Dv FTS_DNR , 21652161Sbostic.Dv FTS_ERR 21752161Sbosticor 21852161Sbostic.Dv FTS_NS , 21952161Sbosticthe 22052161Sbostic.Fa fts_errno 22152161Sbosticfield contains the value of the external variable 22252161Sbostic.Va errno 22352161Sbosticspecifying the cause of the error. 22452161SbosticOtherwise, the contents of the 22552161Sbostic.Fa fts_errno 22652161Sbosticfield are undefined. 22748352Scael.It Fa fts_number 22845617SbosticThis field is provided for the use of the application program and is 22945617Sbosticnot modified by the 23048352Scael.Nm fts 23145617Sbosticfunctions. 23245617SbosticIt is initialized to 0. 23352208SbosticThe 23448352Scael.Fa fts_number 23545617Sbosticand 23648352Scael.Fa fts_pointer 23752208Sbosticfields occupy the same physical location; using both may cause undefined 23852208Sbosticresults. 23948352Scael.It Fa fts_pointer 24045617SbosticThis field is provided for the use of the application program and is 24145617Sbosticnot modified by the 24248352Scael.Nm fts 24345617Sbosticfunctions. 24448352ScaelIt is initialized to 24548352Scael.Dv NULL . 24652208SbosticThe 24748352Scael.Fa fts_number 24845617Sbosticand 24948352Scael.Fa fts_pointer 25052208Sbosticfields occupy the same physical location; using both may cause undefined 25152208Sbosticresults. 25248352Scael.It Fa fts_parent 25348352ScaelA pointer to the 25448352Scael.Fa FTSENT 25548352Scaelstructure referencing the file in the hierarchy 25645617Sbosticimmediately above the current file, i.e. the directory of which this 25745617Sbosticfile is a member. 25845617SbosticA parent structure for the initial entry point is provided as well, 25945617Sbostichowever, only the 26048352Scael.Fa fts_level , 26148352Scael.Fa fts_number 26245617Sbosticand 26348352Scael.Fa fts_pointer 26445617Sbosticfields are guaranteed to be initialized. 26548352Scael.It Fa fts_link 26652075SbosticUpon return from the 26752075Sbostic.Fn fts_children 26852075Sbosticfunction, the 26948352Scael.Fa fts_link 27052075Sbosticfield points to the next structure in the NULL-terminated linked list of 27152075Sbosticdirectory members. 27252075SbosticOtherwise, the contents of the 27352075Sbostic.Fa fts_link 27452075Sbosticfield are undefined. 27552075Sbostic.It Fa fts_cycle 27648352ScaelIf a directory causes a cycle in the hierarchy (see 27748352Scael.Dv FTS_DC ) , 27848352Scaeleither because 27945617Sbosticof a hard link between two directories, or a symbolic link pointing to a 28045617Sbosticdirectory, the 28152075Sbostic.Fa fts_cycle 28248352Scaelfield of the structure will point to the 28348352Scael.Fa FTSENT 28452075Sbosticstructure in the hierarchy that references the same file as the current 28548352Scael.Fa FTSENT 28648352Scaelstructure. 28745617SbosticOtherwise, the contents of the 28852075Sbostic.Fa fts_cycle 28945617Sbosticfield are undefined. 29052227Sbostic.It Fa fts_statp 29152227SbosticA pointer to 29252227Sbostic.Xr stat 2 29339801Sbosticinformation for the file. 29448352Scael.El 29552161Sbostic.Pp 29652161SbosticA single buffer is used for all of the paths of all of the files in the 29752161Sbosticfile hierarchy. 29852161SbosticTherefore, the 29952161Sbostic.Fa fts_path 30052161Sbosticand 30152161Sbostic.Fa fts_accpath 30252161Sbosticfields are guaranteed to be 30352161Sbostic.Dv NULL Ns -terminated 30452161Sbostic.Em only 30552161Sbosticfor the file most recently returned by 30652161Sbostic.Fn fts_read . 30752161SbosticTo use these fields to reference any files represented by other 30852161Sbostic.Fa FTSENT 30952161Sbosticstructures will require that the path buffer be modified using the 31052161Sbosticinformation contained in that 31152161Sbostic.Fa FTSENT 31252161Sbosticstructure's 31352161Sbostic.Fa fts_pathlen 31452161Sbosticfield. 31552161SbosticAny such modifications should be undone before further calls to 31652161Sbostic.Fn fts_read 31752161Sbosticare attempted. 31852161SbosticThe 31952161Sbostic.Fa fts_name 32052161Sbosticfield is always 32152161Sbostic.Dv NULL Ns -terminated. 32248352Scael.Sh FTS_OPEN 32345617SbosticThe 32448352Scael.Fn fts_open 32545617Sbosticfunction takes a pointer to an array of character pointers naming one 32645617Sbosticor more paths which make up a logical file hierarchy to be traversed. 32748352ScaelThe array must be terminated by a 32848352Scael.Dv NULL 32948352Scaelpointer. 33048352Scael.Pp 33148352ScaelThere are 33248352Scaela number of options, at least one of which (either 33348352Scael.Dv FTS_LOGICAL 33448352Scaelor 33548352Scael.Dv FTS_PHYSICAL ) 33648352Scaelmust be specified. 33745617SbosticThe options are selected by 33848352Scael.Em or Ns 'ing 33945617Sbosticthe following values: 34048352Scael.Bl -tag -width "FTS_PHYSICAL" 34152345Sbostic.It Dv FTS_COMFOLLOW 34252345SbosticThis option causes any symbolic link specified as a root path to be 34352345Sbosticfollowed immediately whether or not 34452345Sbostic.Dv FTS_LOGICAL 34552345Sbosticis also specified. 34648352Scael.It Dv FTS_LOGICAL 34745617SbosticThis option causes the 34848352Scael.Nm fts 34948352Scaelroutines to return 35048352Scael.Fa FTSENT 35148352Scaelstructures for the targets of symbolic links 35245617Sbosticinstead of the symbolic links themselves. 35348352ScaelIf this option is set, the only symbolic links for which 35448352Scael.Fa FTSENT 35548352Scaelstructures 35645617Sbosticare returned to the application are those referencing non-existent files. 35748352ScaelEither 35848352Scael.Dv FTS_LOGICAL 35948352Scaelor 36048352Scael.Dv FTS_PHYSICAL 36148352Scael.Em must 36245617Sbosticbe provided to the 36348352Scael.Fn fts_open 36445617Sbosticfunction. 36548352Scael.It Dv FTS_NOCHDIR 36645617SbosticAs a performance optimization, the 36748352Scael.Nm fts 36845617Sbosticfunctions change directories as they walk the file hierarchy. 36945617SbosticThis has the side-effect that an application cannot rely on being 37045617Sbosticin any particular directory during the traversal. 37148352ScaelThe 37248352Scael.Dv FTS_NOCHDIR 37348352Scaeloption turns off this optimization, and the 37448352Scael.Nm fts 37545617Sbosticfunctions will not change the current directory. 37645617SbosticNote that applications should not themselves change their current directory 37748352Scaeland try to access files unless 37848352Scael.Dv FTS_NOCHDIR 37948352Scaelis specified and absolute 38045617Sbosticpathnames were provided as arguments to 38148352Scael.Fn fts_open . 38248352Scael.It Dv FTS_NOSTAT 38348352ScaelBy default, returned 38448352Scael.Fa FTSENT 38552227Sbosticstructures reference file characteristic information (the 38652227Sbostic.Fa statp 38745617Sbosticfield) for each file visited. 38845617SbosticThis option relaxes that requirement as a performance optimization, 38945617Sbosticallowing the 39048352Scael.Nm fts 39145617Sbosticfunctions to set the 39248352Scael.Fa fts_info 39348352Scaelfield to 39448352Scael.Dv FTS_NSOK 39548352Scaeland leave the contents of the 39652227Sbostic.Fa statp 39745617Sbosticfield undefined. 39848352Scael.It Dv FTS_PHYSICAL 39945617SbosticThis option causes the 40048352Scael.Nm fts 40148352Scaelroutines to return 40248352Scael.Fa FTSENT 40348352Scaelstructures for symbolic links themselves instead 40445617Sbosticof the target files they point to. 40548352ScaelIf this option is set, 40648352Scael.Fa FTSENT 40748352Scaelstructures for all symbolic links in the 40845617Sbostichierarchy are returned to the application. 40948352ScaelEither 41048352Scael.Dv FTS_LOGICAL 41148352Scaelor 41248352Scael.Dv FTS_PHYSICAL 41348352Scael.Em must 41445617Sbosticbe provided to the 41548352Scael.Fn fts_open 41645617Sbosticfunction. 41748352Scael.It Dv FTS_SEEDOT 41845617SbosticBy default, unless they are specified as path arguments to 41948352Scael.Fn fts_open , 42048352Scaelany files named 42148352Scael.Ql \&. 42252067Sbosticor 42348352Scael.Ql .. 42452208Sbosticencountered in the file hierarchy are ignored. 42545617SbosticThis option causes the 42648352Scael.Nm fts 42748352Scaelroutines to return 42848352Scael.Fa FTSENT 42948352Scaelstructures for them. 43048352Scael.It Dv FTS_XDEV 43145617SbosticThis option prevents 43248352Scael.Nm fts 43345617Sbosticfrom descending into directories that have a different device number 43445617Sbosticthan the file from which the descent began. 43548352Scael.El 43648352Scael.Pp 43745617SbosticThe argument 43848352Scael.Fn compar 43945617Sbosticspecifies a user-defined function which may be used to order the traversal 44045617Sbosticof the hierarchy. 44148352ScaelIt 44248352Scaeltakes two pointers to pointers to 44348352Scael.Fa FTSENT 44448352Scaelstructures as arguments and 44545617Sbosticshould return a negative value, zero, or a positive value to indicate 44645617Sbosticif the file referenced by its first argument comes before, in any order 44745617Sbosticwith respect to, or after, the file referenced by its second argument. 44839801SbosticThe 44948352Scael.Fa fts_accpath , 45048352Scael.Fa fts_path 45139801Sbosticand 45248352Scael.Fa fts_pathlen 45348352Scaelfields of the 45448352Scael.Fa FTSENT 45548352Scaelstructures may 45648352Scael.Em never 45745617Sbosticbe used in this comparison. 45847194SbosticIf the 45948352Scael.Fa fts_info 46048352Scaelfield is set to 46148352Scael.Dv FTS_NS 46248352Scaelor 46352345Sbostic.Dv FTS_NSOK , 46448352Scaelthe 46552227Sbostic.Fa fts_statp 46645617Sbosticfield may not either. 46745617SbosticIf the 46848352Scael.Fn compar 46948352Scaelargument is 47048352Scael.Dv NULL , 47152345Sbosticthe directory traversal order is in the order listed in 47252345Sbostic.Fa path_argv 47352345Sbosticfor the root paths, and in the order listed in the directory for 47452345Sbosticeverything else. 47548352Scael.Sh FTS_READ 47639801SbosticThe 47748352Scael.Fn fts_read 47848352Scaelfunction returns a pointer to an 47948352Scael.Fa FTSENT 48048352Scaelstructure describing a file in 48145617Sbosticthe hierarchy. 48247194SbosticDirectories (that are readable and do not cause cycles) are visited at 48347194Sbosticleast twice, once in pre-order and once in post-order. 48445617SbosticAll other files are visited at least once. 48545617Sbostic(Hard links between directories that do not cause cycles or symbolic 48645617Sbosticlinks to symbolic links may cause files to be visited more than once, 48745617Sbosticor directories more than twice.) 48848352Scael.Pp 48939801SbosticIf all the members of the hierarchy have been returned, 49048352Scael.Fn fts_read 49148352Scaelreturns 49248352Scael.Dv NULL 49348352Scaeland sets the external variable 49448352Scael.Va errno 49539801Sbosticto 0. 49639801SbosticIf an error unrelated to a file in the hierarchy occurs, 49748352Scael.Fn fts_read 49848352Scaelreturns 49948352Scael.Dv NULL 50048352Scaeland sets 50148352Scael.Va errno 50245617Sbosticappropriately. 50348352ScaelIf an error related to a returned file occurs, a pointer to an 50448352Scael.Fa FTSENT 50545617Sbosticstructure is returned, and 50648352Scael.Va errno 50745617Sbosticmay or may not have been set (see 50848352Scael.Fa fts_info ) . 50948352Scael.Pp 51048352ScaelThe 51148352Scael.Fa FTSENT 51248352Scaelstructures returned by 51348352Scael.Fn fts_read 51445617Sbosticmay be overwritten after a call to 51548352Scael.Fn fts_close 51645617Sbosticon the same file hierarchy stream, or, after a call to 51748352Scael.Fn fts_read 51845617Sbosticon the same file hierarchy stream unless they represent a file of type 51945617Sbosticdirectory, in which case they will not be overwritten until after a call to 52048352Scael.Fn fts_read 52148352Scaelafter the 52248352Scael.Fa FTSENT 52348352Scaelstructure has been returned by the function 52448352Scael.Fn fts_read 52545617Sbosticin post-order. 52648352Scael.Sh FTS_CHILDREN 52745617SbosticThe 52848352Scael.Fn fts_children 52948352Scaelfunction returns a pointer to an 53048352Scael.Fa FTSENT 53152161Sbosticstructure describing the first entry in a NULL-terminated linked list of 53252161Sbosticthe files in the directory represented by the 53348352Scael.Fa FTSENT 53448352Scaelstructure most recently returned by 53548352Scael.Fn fts_read . 53645617SbosticThe list is linked through the 53748352Scael.Fa fts_link 53848352Scaelfield of the 53948352Scael.Fa FTSENT 54052161Sbosticstructure, and is ordered by the user-specified comparison function, if any. 54145617SbosticRepeated calls to 54248352Scael.Fn fts_children 54345617Sbosticwill recreate this linked list. 54448352Scael.Pp 54552161SbosticAs a special case, if 54652161Sbostic.Fn fts_read 54752161Sbostichas not yet been called for a hierarchy, 54852161Sbostic.Fn fts_children 54952161Sbosticwill return a pointer to the files in the logical directory specified to 55052161Sbostic.Fn fts_open , 55152161Sbostici.e. the arguments specified to 55252161Sbostic.Fn fts_open . 55352161SbosticOtherwise, if the 55448352Scael.Fa FTSENT 55548352Scaelstructure most recently returned by 55648352Scael.Fn fts_read 55745617Sbosticis not a directory being visited in pre-order, 55845617Sbosticor the directory does not contain any files, 55948352Scael.Fn fts_children 56048352Scaelreturns 56148352Scael.Dv NULL 56248352Scaeland sets 56348352Scael.Va errno 56445617Sbosticto zero. 56539801SbosticIf an error occurs, 56648352Scael.Fn fts_children 56748352Scaelreturns 56848352Scael.Dv NULL 56948352Scaeland sets 57048352Scael.Va errno 57145617Sbosticappropriately. 57248352Scael.Pp 57348352ScaelThe 57448352Scael.Fa FTSENT 57548352Scaelstructures returned by 57648352Scael.Fn fts_children 57739801Sbosticmay be overwritten after a call to 57852075Sbostic.Fn fts_children , 57948352Scael.Fn fts_close 58039801Sbosticor 58148352Scael.Fn fts_read 58245617Sbosticon the same file hierarchy stream. 583*52769Sbostic.Pp 584*52769Sbostic.Em Option 585*52769Sbosticmay be set to the following value: 586*52769Sbostic.Bl -tag -width FTS_NAMEONLY 587*52769Sbostic.It Dv FTS_NAMEONLY 588*52769SbosticOnly the names of the files are needed. 589*52769SbosticThe contents of all the fields in the returned linked list of structures 590*52769Sbosticare undefined with the exception of the 591*52769Sbostic.Fa fts_name 592*52769Sbosticand 593*52769Sbostic.Fa fts_namelen 594*52769Sbosticfields. 595*52769Sbostic.El 59648352Scael.Sh FTS_SET 59745617SbosticThe function 59848352Scael.Fn fts_set 59939801Sbosticallows the user application to determine further processing for the 60039801Sbosticfile 60148352Scael.Fa f 60239801Sbosticof the stream 60348352Scael.Fa ftsp . 60448352ScaelThe 60548352Scael.Fn fts_set 60648352Scaelfunction 60748352Scaelreturns 0 on success, and \-1 if an error occurs. 60848352Scael.Em Option 60945617Sbosticmust be set to one of the following values: 61048352Scael.Bl -tag -width FTS_PHYSICAL 61148352Scael.It Dv FTS_AGAIN 61239801SbosticRe-visit the file; any file type may be re-visited. 61339801SbosticThe next call to 61448352Scael.Fn fts_read 61539801Sbosticwill return the referenced file. 61645617SbosticThe 61748352Scael.Fa fts_stat 61839801Sbosticand 61948352Scael.Fa fts_info 62039801Sbosticfields of the structure will be reinitialized at that time, 62145617Sbosticbut no other fields will have been changed. 62239801SbosticThis option is meaningful only for the most recently returned 62339801Sbosticfile from 62448352Scael.Fn fts_read . 62539801SbosticNormal use is for post-order directory visits, where it causes the 62639801Sbosticdirectory to be re-visited (in both pre and post-order) as well as all 62739801Sbosticof its descendants. 62848352Scael.It Dv FTS_FOLLOW 62939801SbosticThe referenced file must be a symbolic link. 63039801SbosticIf the referenced file is the one most recently returned by 63148352Scael.Fn fts_read , 63239801Sbosticthe next call to 63348352Scael.Fn fts_read 63439801Sbosticreturns the file with the 63548352Scael.Fa fts_info 63639801Sbosticand 63752227Sbostic.Fa fts_statp 63839801Sbosticfields reinitialized to reflect the target of the symbolic link instead 63939801Sbosticof the symbolic link itself. 64039801SbosticIf the file is one of those most recently returned by 64148352Scael.Fn fts_children , 64239801Sbosticthe 64348352Scael.Fa fts_info 64439801Sbosticand 64552227Sbostic.Fa fts_statp 64639801Sbosticfields of the structure, when returned by 64748352Scael.Fn fts_read , 64839801Sbosticwill reflect the target of the symbolic link instead of the symbolic link 64939801Sbosticitself. 65047194SbosticIn either case, if the target of the symbolic link does not exist the 65147194Sbosticfields of the returned structure will be unchanged and the 65248352Scael.Fa fts_info 65348352Scaelfield will be set to 65448352Scael.Dv FTS_SLNONE . 65548352Scael.Pp 65647194SbosticIf the target of the link is a directory, the pre-order return, followed 65747194Sbosticby the return of all of its descendants, followed by a post-order return, 65847194Sbosticis done. 65948352Scael.It Dv FTS_SKIP 66039801SbosticNo descendants of this file are visited. 66145617SbosticThe file may be one of those most recently returned by either 66248352Scael.Fn fts_children 66345617Sbosticor 66448352Scael.Fn fts_read . 66548352Scael.El 66648352Scael.Sh FTS_CLOSE 66745617SbosticThe 66848352Scael.Fn fts_close 66945617Sbosticfunction closes a file hierarchy stream 67048352Scael.Fa ftsp 67145617Sbosticand restores the current directory to the directory from which 67248352Scael.Fn fts_open 67345617Sbosticwas called to open 67448352Scael.Fa ftsp . 67548352ScaelThe 67648352Scael.Fn fts_close 67748352Scaelfunction 67848352Scaelreturns 0 on success, and \-1 if an error occurs. 67948352Scael.Sh ERRORS 68048352ScaelThe function 68148352Scael.Fn fts_open 682*52769Sbosticmay fail and set 683*52769Sbostic.Va errno 684*52769Sbosticfor any of the errors specified for the library functions 68548352Scael.Xr open 2 68645661Sbosticand 68748352Scael.Xr malloc 3 . 68848352Scael.Pp 68948352ScaelThe function 69048352Scael.Fn fts_close 691*52769Sbosticmay fail and set 692*52769Sbostic.Va errno 693*52769Sbosticfor any of the errors specified for the library functions 69448352Scael.Xr chdir 2 69545661Sbosticand 69648352Scael.Xr close 2 . 69748352Scael.Pp 69848352ScaelThe functions 69950943Sbostic.Fn fts_read 70039801Sbosticand 70148352Scael.Fn fts_children 702*52769Sbosticmay fail and set 703*52769Sbostic.Va errno 704*52769Sbosticfor any of the errors specified for the library functions 70548352Scael.Xr chdir 2 , 70648352Scael.Xr malloc 3 , 70748352Scael.Xr opendir 3 , 70848352Scael.Xr readdir 3 70939801Sbosticand 71048352Scael.Xr stat 2 . 711*52769Sbostic.Pp 712*52769SbosticIn addition, 713*52769Sbostic.Fn fts_children , 714*52769Sbostic.Fn fts_open 715*52769Sbosticand 716*52769Sbostic.Fn fts_set 717*52769Sbosticmay fail and set 718*52769Sbostic.Va errno 719*52769Sbosticas follows: 720*52769Sbostic.Bl -tag -width Er 721*52769Sbostic.It Bq Er EINVAL 722*52769SbosticThe options were invalid. 723*52769Sbostic.EL 72448352Scael.Sh SEE ALSO 72548352Scael.Xr find 1 , 72648352Scael.Xr chdir 2 , 72748352Scael.Xr stat 2 , 72848352Scael.Xr qsort 3 72948352Scael.Sh STANDARDS 73039801SbosticThe 73148352Scael.Nm fts 73248352Scaelutility is expected to be a superset of the 73348352Scael.St -p1003.1-88 73447194Sbosticspecification. 735