xref: /csrg-svn/lib/libc/gen/fts.3 (revision 48352)
1*48352Scael.\" Copyright (c) 1989, 1991 The Regents of the University of California.
239801Sbostic.\" All rights reserved.
339801Sbostic.\"
443571Strent.\" %sccs.include.redist.man%
539801Sbostic.\"
6*48352Scael.\"     @(#)fts.3	5.10 (Berkeley) 04/19/91
739801Sbostic.\"
8*48352Scael.Dd
9*48352Scael.Dt FTS 3
10*48352Scael.Os
11*48352Scael.Sh NAME
12*48352Scael.Nm fts
13*48352Scael.Nd traverse a file hierarchy
14*48352Scael.Sh SYNOPSIS
15*48352Scael.Fd #include <sys/types.h>
16*48352Scael.Fd #include <sys/stat.h>
17*48352Scael.Fd #include <fts.h>
18*48352Scael.Ft FTS *
19*48352Scael.Fn fts_open "char * const *path_argv" "int options" "int *compar(const FTSENT *, const FTSENT *)"
20*48352Scael.Ft FTSENT *
21*48352Scael.Fn fts_read "FTS *ftsp"
22*48352Scael.Ft FTSENT *
23*48352Scael.Fn fts_children "FTS *ftsp"
24*48352Scael.Ft int
25*48352Scael.Fn fts_set "FTS ftsp" "FTSENT *f" "int options"
26*48352Scael.Ft int
27*48352Scael.Fn fts_close "FTS *ftsp"
28*48352Scael.Sh DESCRIPTION
2939801SbosticThe
30*48352Scael.Nm fts
31*48352Scaelfunctions are provided for traversing
32*48352Scael.Tn UNIX
33*48352Scaelfile hierarchies.
34*48352Scael.Pp
3547194SbosticThe simple overview is that the
36*48352Scael.Fn fts_open
3747194Sbosticfunction returns a ``handle'' on a file hierarchy, which is supplied to
3847194Sbosticthe other
39*48352Scael.Nm fts
4045617Sbosticfunctions to determine which hierarchy they operate on.
4145617SbosticThe function
42*48352Scael.Fn fts_read
4345617Sbosticreturns a pointer to a structure describing one of the files in the file
4445617Sbostichierarchy.
4545617SbosticThe function
46*48352Scael.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.
56*48352Scael.Pp
57*48352ScaelTwo structures are defined (and typedef'd) in the include file
58*48352Scael.Aq Pa fts.h .
59*48352ScaelThe first is
60*48352Scael.Fa FTS ,
61*48352Scaelthe structure that represents the file hierarchy stream.
62*48352ScaelThe second is
63*48352Scael.Fa FTSENT ,
64*48352Scaelthe structure that represents a file in the file
6545617Sbostichierarchy.
66*48352ScaelNormally, an
67*48352Scael.Fa FTSENT
68*48352Scaelstructure is returned for every file in the file
6945617Sbostichierarchy.
70*48352ScaelIn this manual page, ``file'' and
71*48352Scael.Dq Fa FTSENT No structure
72*48352Scaelare generally
7345617Sbosticinterchangeable.
74*48352ScaelThe
75*48352Scael.Fa FTSENT
76*48352Scaelstructure contains at least the following fields, which are
7745617Sbosticdescribed in greater detail below:
78*48352Scael.Bd -literal -offset indent
7945617Sbostictypedef struct _ftsent {
80*48352Scael	u_short fts_info;		/* flags for FTSENT structure */
81*48352Scael	char *fts_accpath;		/* access path */
8245617Sbostic	char *fts_path;			/* root path */
83*48352Scael	short fts_pathlen;		/* strlen(fts_path) */
8442273Sbostic	char *fts_name;			/* file name */
85*48352Scael	short fts_namelen;		/* strlen(fts_name) */
86*48352Scael	short fts_level;		/* depth (\-1 to N) */
87*48352Scael	long fts_number;		/* local numeric value */
8845617Sbostic	void *fts_pointer;		/* local address value */
89*48352Scael	struct ftsent *fts_parent;	/* parent directory */
90*48352Scael	struct ftsent *fts_link;	/* cycle or next file structure */
91*48352Scael	struct stat fts_statb;		/* stat(2) information */
9239801Sbostic} FTSENT;
93*48352Scael.Ed
94*48352Scael.Pp
9545617SbosticThese fields are defined as follows:
96*48352Scael.Bl -tag -width "fts_namelen"
97*48352Scael.It Fa fts_info
98*48352ScaelOne of the following flags describing the returned
99*48352Scael.Fa FTSENT
100*48352Scaelstructure and
10145617Sbosticthe file it represents.
102*48352ScaelWith the exception of directories without errors
103*48352Scael.Pq Dv FTS_D ,
104*48352Scaelall of these
10545617Sbosticentries are terminal, that is, they will not be revisited, nor will any
10645617Sbosticof their descendants be visited.
107*48352Scael.Bl  -tag -width FTS_DEFAULT
108*48352Scael.It Dv FTS_D
10939801SbosticA directory being visited in pre-order.
110*48352Scael.It Dv FTS_DC
11145617SbosticA directory that causes a cycle in the tree.
11245617Sbostic(The
113*48352Scael.Fa fts_link
114*48352Scaelfield of the
115*48352Scael.Fa FTSENT
116*48352Scaelstructure will be filled in as well.)
117*48352Scael.It Dv FTS_DEFAULT
118*48352ScaelAny
119*48352Scael.Fa FTSENT
120*48352Scaelstructure that represents a file type not explicitly described
12145617Sbosticby one of the other
122*48352Scael.Fa fts_info
12345617Sbosticvalues.
124*48352Scael.It Dv FTS_DNR
12545617SbosticA directory which cannot be read.
12647194SbosticAn error return; the external variable
127*48352Scael.Va errno
12847194Sbosticwill be set to indicate the error.
129*48352Scael.It Dv FTS_DOT
130*48352ScaelA file named
131*48352Scael.Ql \&.
132*48352Scaelor
133*48352Scael.Ql ..
134*48352Scaelwhich was not specified as a file name to
135*48352Scael.Fn fts_open
136*48352Scael(see
137*48352Scael.Dv FTS_SEEDOT ) .
138*48352Scael.It Dv FTS_DP
13945617SbosticA directory being visited in post-order.
140*48352ScaelThe contents of the
141*48352Scael.Fa FTSENT
142*48352Scaelstructure will be unchanged from when
14345617Sbosticit was returned in pre-order, i.e. with the
144*48352Scael.Fa fts_info
145*48352Scaelfield set to
146*48352Scael.Dv FTS_D .
147*48352Scael.It Dv FTS_ERR
14845617SbosticAn error return; the external variable
149*48352Scael.Va errno
15045617Sbosticwill be set to indicate the error.
151*48352Scael.It Dv FTS_F
15239801SbosticA regular file.
153*48352Scael.It Dv FTS_NS
15445617SbosticA file for which no
155*48352Scael.Xr stat 2
15647194Sbosticinformation was available.
15747194SbosticThe contents of the
158*48352Scael.Fa fts_statb
15939801Sbosticfield are undefined.
16047194SbosticAn error return; the external variable
161*48352Scael.Va errno
16247194Sbosticwill be set to indicate the error.
163*48352Scael.It Dv FTS_NSOK
16447194SbosticA file for which no
165*48352Scael.Xr stat 2
16647194Sbosticinformation was requested.
16747194SbosticThe contents of the
168*48352Scael.Fa fts_statb
16947194Sbosticfield are undefined.
170*48352Scael.It Dv FTS_SL
17139801SbosticA symbolic link.
172*48352Scael.It Dv FTS_SLNONE
17339801SbosticA symbolic link with a non-existent target.
17447194SbosticThe contents of the
175*48352Scael.Fa fts_statb
17647194Sbosticfield contain the file characteristic information for the symbolic link
17747194Sbosticitself.
178*48352Scael.El
179*48352Scael.It Fa fts_accpath
18047194SbosticA path for accessing the file from the current directory.
181*48352Scael.It Fa fts_path
18245617SbosticThe path for the file relative to the root of the traversal.
18345617SbosticThis path contains the path specified to
184*48352Scael.Fn fts_open
18545617Sbosticas a prefix.
186*48352Scael.It Fa fts_pathlen
18745617SbosticThe length of the string referenced by
188*48352Scael.Fa fts_path .
189*48352Scael.It Fa fts_name
19045617SbosticThe name of the file.
191*48352Scael.It Fa fts_namelen
19245617SbosticThe length of the string referenced by
193*48352Scael.Fa fts_name .
194*48352Scael.It Fa fts_level
19545617SbosticThe depth of the traversal, numbered from \-1 to N, where this file
19645617Sbosticwas found.
197*48352ScaelThe
198*48352Scael.Fa FTSENT
199*48352Scaelstructure representing the parent of the starting point (or root)
200*48352Scaelof the traversal is numbered \-1, and the
201*48352Scael.Fa FTSENT
202*48352Scaelstructure for the root
20345617Sbosticitself is numbered 0.
204*48352Scael.It Fa fts_number
20545617SbosticThis field is provided for the use of the application program and is
20645617Sbosticnot modified by the
207*48352Scael.Nm fts
20845617Sbosticfunctions.
20945617SbosticIt is initialized to 0.
21045617SbosticThe fields
211*48352Scael.Fa fts_number
21245617Sbosticand
213*48352Scael.Fa fts_pointer
21445617Sbosticoccupy the same physical location; using both may cause undefined results.
215*48352Scael.It Fa fts_pointer
21645617SbosticThis field is provided for the use of the application program and is
21745617Sbosticnot modified by the
218*48352Scael.Nm fts
21945617Sbosticfunctions.
220*48352ScaelIt is initialized to
221*48352Scael.Dv NULL .
22245617SbosticThe fields
223*48352Scael.Fa fts_number
22445617Sbosticand
225*48352Scael.Fa fts_pointer
22645617Sbosticoccupy the same physical location; using both may cause undefined results.
227*48352Scael.It Fa fts_parent
228*48352ScaelA pointer to the
229*48352Scael.Fa FTSENT
230*48352Scaelstructure referencing the file in the hierarchy
23145617Sbosticimmediately above the current file, i.e. the directory of which this
23245617Sbosticfile is a member.
23345617SbosticA parent structure for the initial entry point is provided as well,
23445617Sbostichowever, only the
235*48352Scael.Fa fts_level ,
236*48352Scael.Fa fts_number
23745617Sbosticand
238*48352Scael.Fa fts_pointer
23945617Sbosticfields are guaranteed to be initialized.
240*48352Scael.It Fa fts_link
24145617SbosticThe
242*48352Scael.Fa fts_link
24345617Sbosticfield has two separate uses.
244*48352ScaelIf a directory causes a cycle in the hierarchy (see
245*48352Scael.Dv FTS_DC ) ,
246*48352Scaeleither because
24745617Sbosticof a hard link between two directories, or a symbolic link pointing to a
24845617Sbosticdirectory, the
249*48352Scael.Fa fts_link
250*48352Scaelfield of the structure will point to the
251*48352Scael.Fa FTSENT
252*48352Scaelstructure in the hierarchy
253*48352Scaelthat references the same file as the current
254*48352Scael.Fa FTSENT
255*48352Scaelstructure.
25645617SbosticAlso, upon return from the
257*48352Scael.Fn fts_children
25845617Sbosticfunction, the
259*48352Scael.Fa fts_link
26045617Sbosticfield points to the next structure in the linked list of directory members.
26145617SbosticOtherwise, the contents of the
262*48352Scael.Fa fts_link
26345617Sbosticfield are undefined.
264*48352Scael.It Fa fts_statb
265*48352Scael.Xr Stat 2
26639801Sbosticinformation for the file.
267*48352Scael.El
268*48352Scael.Sh FTS_OPEN
26945617SbosticThe
270*48352Scael.Fn fts_open
27145617Sbosticfunction takes a pointer to an array of character pointers naming one
27245617Sbosticor more paths which make up a logical file hierarchy to be traversed.
273*48352ScaelThe array must be terminated by a
274*48352Scael.Dv NULL
275*48352Scaelpointer.
276*48352Scael.Pp
277*48352ScaelThere are
278*48352Scaela number of options, at least one of which (either
279*48352Scael.Dv FTS_LOGICAL
280*48352Scaelor
281*48352Scael.Dv FTS_PHYSICAL )
282*48352Scaelmust be specified.
28345617SbosticThe options are selected by
284*48352Scael.Em or Ns 'ing
28545617Sbosticthe following values:
286*48352Scael.Bl -tag -width "FTS_PHYSICAL"
287*48352Scael.It Dv FTS_LOGICAL
28845617SbosticThis option causes the
289*48352Scael.Nm fts
290*48352Scaelroutines to return
291*48352Scael.Fa FTSENT
292*48352Scaelstructures for the targets of symbolic links
29345617Sbosticinstead of the symbolic links themselves.
294*48352ScaelIf this option is set, the only symbolic links for which
295*48352Scael.Fa FTSENT
296*48352Scaelstructures
29745617Sbosticare returned to the application are those referencing non-existent files.
298*48352ScaelEither
299*48352Scael.Dv FTS_LOGICAL
300*48352Scaelor
301*48352Scael.Dv FTS_PHYSICAL
302*48352Scael.Em must
30345617Sbosticbe provided to the
304*48352Scael.Fn fts_open
30545617Sbosticfunction.
306*48352Scael.It Dv FTS_NOCHDIR
30745617SbosticAs a performance optimization, the
308*48352Scael.Nm fts
30945617Sbosticfunctions change directories as they walk the file hierarchy.
31045617SbosticThis has the side-effect that an application cannot rely on being
31145617Sbosticin any particular directory during the traversal.
312*48352ScaelThe
313*48352Scael.Dv FTS_NOCHDIR
314*48352Scaeloption turns off this optimization, and the
315*48352Scael.Nm fts
31645617Sbosticfunctions will not change the current directory.
31745617SbosticNote that applications should not themselves change their current directory
318*48352Scaeland try to access files unless
319*48352Scael.Dv FTS_NOCHDIR
320*48352Scaelis specified and absolute
32145617Sbosticpathnames were provided as arguments to
322*48352Scael.Fn fts_open .
323*48352Scael.It Dv FTS_NOSTAT
324*48352ScaelBy default, returned
325*48352Scael.Fa FTSENT
326*48352Scaelstructures contain file characteristic
32745617Sbosticinformation (the
328*48352Scael.Fa statb
32945617Sbosticfield) for each file visited.
33045617SbosticThis option relaxes that requirement as a performance optimization,
33145617Sbosticallowing the
332*48352Scael.Nm fts
33345617Sbosticfunctions to set the
334*48352Scael.Fa fts_info
335*48352Scaelfield to
336*48352Scael.Dv FTS_NSOK
337*48352Scaeland leave the contents of the
338*48352Scael.Fa statb
33945617Sbosticfield undefined.
340*48352Scael.It Dv FTS_PHYSICAL
34145617SbosticThis option causes the
342*48352Scael.Nm fts
343*48352Scaelroutines to return
344*48352Scael.Fa FTSENT
345*48352Scaelstructures for symbolic links themselves instead
34645617Sbosticof the target files they point to.
347*48352ScaelIf this option is set,
348*48352Scael.Fa FTSENT
349*48352Scaelstructures for all symbolic links in the
35045617Sbostichierarchy are returned to the application.
351*48352ScaelEither
352*48352Scael.Dv FTS_LOGICAL
353*48352Scaelor
354*48352Scael.Dv FTS_PHYSICAL
355*48352Scael.Em must
35645617Sbosticbe provided to the
357*48352Scael.Fn fts_open
35845617Sbosticfunction.
359*48352Scael.It Dv FTS_SEEDOT
36045617SbosticBy default, unless they are specified as path arguments to
361*48352Scael.Fn fts_open ,
362*48352Scaelany files named
363*48352Scael.Ql \&.
364*48352Scaeland
365*48352Scael.Ql ..
366*48352Scaelencountered in the file hierarchy are
36745617Sbosticignored.
36845617SbosticThis option causes the
369*48352Scael.Nm fts
370*48352Scaelroutines to return
371*48352Scael.Fa FTSENT
372*48352Scaelstructures for them.
373*48352Scael.It Dv FTS_XDEV
37445617SbosticThis option prevents
375*48352Scael.Nm fts
37645617Sbosticfrom descending into directories that have a different device number
37745617Sbosticthan the file from which the descent began.
378*48352Scael.El
379*48352Scael.Pp
38045617SbosticThe argument
381*48352Scael.Fn compar
38245617Sbosticspecifies a user-defined function which may be used to order the traversal
38345617Sbosticof the hierarchy.
384*48352ScaelIt
385*48352Scaeltakes two pointers to pointers to
386*48352Scael.Fa FTSENT
387*48352Scaelstructures as arguments and
38845617Sbosticshould return a negative value, zero, or a positive value to indicate
38945617Sbosticif the file referenced by its first argument comes before, in any order
39045617Sbosticwith respect to, or after, the file referenced by its second argument.
39139801SbosticThe
392*48352Scael.Fa fts_accpath ,
393*48352Scael.Fa fts_path
39439801Sbosticand
395*48352Scael.Fa fts_pathlen
396*48352Scaelfields of the
397*48352Scael.Fa FTSENT
398*48352Scaelstructures may
399*48352Scael.Em never
40045617Sbosticbe used in this comparison.
40147194SbosticIf the
402*48352Scael.Fa fts_info
403*48352Scaelfield is set to
404*48352Scael.Dv FTS_NS
405*48352Scaelor
406*48352Scael.DV FTS_NSOK ,
407*48352Scaelthe
408*48352Scael.Fa fts_stab
40945617Sbosticfield may not either.
41045617SbosticIf the
411*48352Scael.Fn compar
412*48352Scaelargument is
413*48352Scael.Dv NULL ,
414*48352Scaelthe directory traversal order is unspecified except
41545617Sbosticfor the root paths which are traversed in the order listed in
416*48352Scael.Fa path_argv .
417*48352Scael.Sh FTS_READ
41839801SbosticThe
419*48352Scael.Fn fts_read
420*48352Scaelfunction returns a pointer to an
421*48352Scael.Fa FTSENT
422*48352Scaelstructure describing a file in
42345617Sbosticthe hierarchy.
42447194SbosticDirectories (that are readable and do not cause cycles) are visited at
42547194Sbosticleast twice, once in pre-order and once in post-order.
42645617SbosticAll other files are visited at least once.
42745617Sbostic(Hard links between directories that do not cause cycles or symbolic
42845617Sbosticlinks to symbolic links may cause files to be visited more than once,
42945617Sbosticor directories more than twice.)
430*48352Scael.Pp
43139801SbosticIf all the members of the hierarchy have been returned,
432*48352Scael.Fn fts_read
433*48352Scaelreturns
434*48352Scael.Dv NULL
435*48352Scaeland sets the external variable
436*48352Scael.Va errno
43739801Sbosticto 0.
43839801SbosticIf an error unrelated to a file in the hierarchy occurs,
439*48352Scael.Fn fts_read
440*48352Scaelreturns
441*48352Scael.Dv NULL
442*48352Scaeland sets
443*48352Scael.Va errno
44445617Sbosticappropriately.
445*48352ScaelIf an error related to a returned file occurs, a pointer to an
446*48352Scael.Fa FTSENT
44745617Sbosticstructure is returned, and
448*48352Scael.Va errno
44945617Sbosticmay or may not have been set (see
450*48352Scael.Fa fts_info ) .
451*48352Scael.Pp
452*48352ScaelThe
453*48352Scael.Fa FTSENT
454*48352Scaelstructures returned by
455*48352Scael.Fn fts_read
45645617Sbosticmay be overwritten after a call to
457*48352Scael.Fn fts_close
45845617Sbosticon the same file hierarchy stream, or, after a call to
459*48352Scael.Fn fts_read
46045617Sbosticon the same file hierarchy stream unless they represent a file of type
46145617Sbosticdirectory, in which case they will not be overwritten until after a call to
462*48352Scael.Fn fts_read
463*48352Scaelafter the
464*48352Scael.Fa FTSENT
465*48352Scaelstructure has been returned by the function
466*48352Scael.Fn fts_read
46745617Sbosticin post-order.
468*48352Scael.Sh FTS_CHILDREN
46945617SbosticThe
470*48352Scael.Fn fts_children
471*48352Scaelfunction returns a pointer to an
472*48352Scael.Fa FTSENT
473*48352Scaelstructure describing the first
47445617Sbosticentry in a linked list of the files in the directory represented by the
475*48352Scael.Fa FTSENT
476*48352Scaelstructure most recently returned by
477*48352Scael.Fn fts_read .
47845617SbosticThe list is linked through the
479*48352Scael.Fa fts_link
480*48352Scaelfield of the
481*48352Scael.Fa FTSENT
482*48352Scaelstructure, and is ordered by the user-specified
48345617Sbosticcomparison function, if any.
48445617SbosticRepeated calls to
485*48352Scael.Fn fts_children
48645617Sbosticwill recreate this linked list.
487*48352Scael.Pp
488*48352ScaelIf the
489*48352Scael.Fa FTSENT
490*48352Scaelstructure most recently returned by
491*48352Scael.Fn fts_read
49245617Sbosticis not a directory being visited in pre-order,
49345617Sbosticor the directory does not contain any files,
494*48352Scael.Fn fts_children
495*48352Scaelreturns
496*48352Scael.Dv NULL
497*48352Scaeland sets
498*48352Scael.Va errno
49945617Sbosticto zero.
50039801SbosticIf an error occurs,
501*48352Scael.Fn fts_children
502*48352Scaelreturns
503*48352Scael.Dv NULL
504*48352Scaeland sets
505*48352Scael.Va errno
50645617Sbosticappropriately.
507*48352Scael.Pp
508*48352ScaelThe
509*48352Scael.Fa FTSENT
510*48352Scaelstructures returned by
511*48352Scael.Fn fts_children
51239801Sbosticmay be overwritten after a call to
513*48352Scael.Fn fts_close
51445617Sbosticon the same file hierarchy stream, or after a call to
515*48352Scael.Fn fts_children
51639801Sbosticor
517*48352Scael.Fn fts_read
51845617Sbosticon the same file hierarchy stream.
519*48352Scael.Pp
52045617SbosticA single buffer is used for all of the paths of all of the files in the
52145617Sbosticfile hierarchy.
52245617SbosticTherefore, the
523*48352Scael.Fa fts_path
52445617Sbosticand
525*48352Scael.Fa fts_accpath
526*48352Scaelfields are guaranteed to be
527*48352Scael.Dv NULL Ns -terminated
528*48352Scael.Em only
52945617Sbosticfor the file most recently returned by
530*48352Scael.Fn fts_read .
531*48352ScaelTo use these fields to reference any files represented by other
532*48352Scael.Fa FTSENT
53345617Sbosticstructures will require that the path buffer be modified using the
534*48352Scaelinformation contained in that
535*48352Scael.Fa FTSENT
536*48352Scaelstructure's
537*48352Scael.Fa fts_pathlen
53845617Sbosticfield.
53945617SbosticAny such modifications should be undone before further calls to
540*48352Scael.Fn fts_read
54145617Sbosticare attempted.
54245617SbosticThe
543*48352Scael.Fa fts_name
544*48352Scaelfield is always
545*48352Scael.Dv NULL Ns -terminated.
546*48352Scael.Sh FTS_SET
54745617SbosticThe function
548*48352Scael.Fn fts_set
54939801Sbosticallows the user application to determine further processing for the
55039801Sbosticfile
551*48352Scael.Fa f
55239801Sbosticof the stream
553*48352Scael.Fa ftsp .
554*48352ScaelThe
555*48352Scael.Fn fts_set
556*48352Scaelfunction
557*48352Scaelreturns 0 on success, and \-1 if an error occurs.
558*48352Scael.Em Option
55945617Sbosticmust be set to one of the following values:
560*48352Scael.Bl -tag -width FTS_PHYSICAL
561*48352Scael.It Dv FTS_AGAIN
56239801SbosticRe-visit the file; any file type may be re-visited.
56339801SbosticThe next call to
564*48352Scael.Fn fts_read
56539801Sbosticwill return the referenced file.
56645617SbosticThe
567*48352Scael.Fa fts_stat
56839801Sbosticand
569*48352Scael.Fa fts_info
57039801Sbosticfields of the structure will be reinitialized at that time,
57145617Sbosticbut no other fields will have been changed.
57239801SbosticThis option is meaningful only for the most recently returned
57339801Sbosticfile from
574*48352Scael.Fn fts_read .
57539801SbosticNormal use is for post-order directory visits, where it causes the
57639801Sbosticdirectory to be re-visited (in both pre and post-order) as well as all
57739801Sbosticof its descendants.
578*48352Scael.It Dv FTS_FOLLOW
57939801SbosticThe referenced file must be a symbolic link.
58039801SbosticIf the referenced file is the one most recently returned by
581*48352Scael.Fn fts_read ,
58239801Sbosticthe next call to
583*48352Scael.Fn fts_read
58439801Sbosticreturns the file with the
585*48352Scael.Fa fts_info
58639801Sbosticand
587*48352Scael.Fa fts_statb
58839801Sbosticfields reinitialized to reflect the target of the symbolic link instead
58939801Sbosticof the symbolic link itself.
59039801SbosticIf the file is one of those most recently returned by
591*48352Scael.Fn fts_children ,
59239801Sbosticthe
593*48352Scael.Fa fts_info
59439801Sbosticand
595*48352Scael.Fa fts_statb
59639801Sbosticfields of the structure, when returned by
597*48352Scael.Fn fts_read ,
59839801Sbosticwill reflect the target of the symbolic link instead of the symbolic link
59939801Sbosticitself.
60047194SbosticIn either case, if the target of the symbolic link does not exist the
60147194Sbosticfields of the returned structure will be unchanged and the
602*48352Scael.Fa fts_info
603*48352Scaelfield will be set to
604*48352Scael.Dv FTS_SLNONE .
605*48352Scael.Pp
60647194SbosticIf the target of the link is a directory, the pre-order return, followed
60747194Sbosticby the return of all of its descendants, followed by a post-order return,
60847194Sbosticis done.
609*48352Scael.It Dv FTS_SKIP
61039801SbosticNo descendants of this file are visited.
61145617SbosticThe file may be one of those most recently returned by either
612*48352Scael.Fn fts_children
61345617Sbosticor
614*48352Scael.Fn fts_read .
615*48352Scael.El
616*48352Scael.Sh FTS_CLOSE
61745617SbosticThe
618*48352Scael.Fn fts_close
61945617Sbosticfunction closes a file hierarchy stream
620*48352Scael.Fa ftsp
62145617Sbosticand restores the current directory to the directory from which
622*48352Scael.Fn fts_open
62345617Sbosticwas called to open
624*48352Scael.Fa ftsp .
625*48352ScaelThe
626*48352Scael.Fn fts_close
627*48352Scaelfunction
628*48352Scaelreturns 0 on success, and \-1 if an error occurs.
629*48352Scael.Sh ERRORS
630*48352ScaelThe function
631*48352Scael.Fn fts_open
63239801Sbosticmay fail and set errno for any of the errors specified for the library
63345661Sbosticfunctions
634*48352Scael.Xr open 2
63545661Sbosticand
636*48352Scael.Xr malloc 3 .
637*48352Scael.Pp
638*48352ScaelThe function
639*48352Scael.Fn fts_close
64039801Sbosticmay fail and set errno for any of the errors specified for the library
64145661Sbosticfunctions
642*48352Scael.Xr chdir 2
64345661Sbosticand
644*48352Scael.Xr close 2 .
645*48352Scael.Pp
646*48352ScaelThe functions
647*48352Scael.Fn Fts_read
64839801Sbosticand
649*48352Scael.Fn fts_children
65039801Sbosticmay fail and set errno for any of the errors specified for the library
65145617Sbosticfunctions
652*48352Scael.Xr chdir 2 ,
653*48352Scael.Xr malloc 3 ,
654*48352Scael.Xr opendir 3 ,
655*48352Scael.Xr readdir 3
65639801Sbosticand
657*48352Scael.Xr stat 2 .
658*48352Scael.Sh SEE ALSO
659*48352Scael.Xr find 1 ,
660*48352Scael.Xr chdir 2 ,
661*48352Scael.Xr stat 2 ,
662*48352Scael.Xr qsort 3
663*48352Scael.Sh STANDARDS
66439801SbosticThe
665*48352Scael.Nm fts
666*48352Scaelutility is expected to be a superset of the
667*48352Scael.St -p1003.1-88
66847194Sbosticspecification.
669