xref: /csrg-svn/lib/libc/gen/fts.3 (revision 52208)
148352Scael.\" Copyright (c) 1989, 1991 The Regents of the University of California.
239801Sbostic.\" All rights reserved.
339801Sbostic.\"
443571Strent.\" %sccs.include.redist.man%
539801Sbostic.\"
6*52208Sbostic.\"     @(#)fts.3	5.16 (Berkeley) 01/15/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.
34*52208SbosticA simple overview is that the
3548352Scael.Fn fts_open
36*52208Sbosticfunction returns a ``handle'' on a file hierarchy, which is then supplied to
3747194Sbosticthe other
3848352Scael.Nm fts
39*52208Sbosticfunctions.
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 ,
60*52208Sbosticthe 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) */
86*52208Sbostic	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 */
9248352Scael	struct stat fts_statb;		/* 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.
130*52208Sbostic.It Dv FTS_DOT
131*52208SbosticA file named
132*52208Sbostic.Ql \&.
133*52208Sbosticor
134*52208Sbostic.Ql ..
135*52208Sbosticwhich was not specified as a file name to
136*52208Sbostic.Fn fts_open
137*52208Sbostic(see
138*52208Sbostic.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
15948352Scael.Fa fts_statb
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
16948352Scael.Fa fts_statb
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
17648352Scael.Fa fts_statb
17747194Sbosticfield contain 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
206*52208SbosticUpon return of a
207*52208Sbostic.Fa FTSENT
208*52208Sbosticstructure from the
20952161Sbostic.Fn fts_children
21052161Sbosticor
21152161Sbostic.Fn fts_read
21252161Sbosticfunctions, with its
21352161Sbostic.Fa fts_info
21452161Sbosticfield set to
215*52208Sbostic.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.
233*52208SbosticThe
23448352Scael.Fa fts_number
23545617Sbosticand
23648352Scael.Fa fts_pointer
237*52208Sbosticfields occupy the same physical location; using both may cause undefined
238*52208Sbosticresults.
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 .
246*52208SbosticThe
24748352Scael.Fa fts_number
24845617Sbosticand
24948352Scael.Fa fts_pointer
250*52208Sbosticfields occupy the same physical location; using both may cause undefined
251*52208Sbosticresults.
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.
29048352Scael.It Fa fts_statb
29148352Scael.Xr Stat 2
29239801Sbosticinformation for the file.
29348352Scael.El
29452161Sbostic.Pp
29552161SbosticA single buffer is used for all of the paths of all of the files in the
29652161Sbosticfile hierarchy.
29752161SbosticTherefore, the
29852161Sbostic.Fa fts_path
29952161Sbosticand
30052161Sbostic.Fa fts_accpath
30152161Sbosticfields are guaranteed to be
30252161Sbostic.Dv NULL Ns -terminated
30352161Sbostic.Em only
30452161Sbosticfor the file most recently returned by
30552161Sbostic.Fn fts_read .
30652161SbosticTo use these fields to reference any files represented by other
30752161Sbostic.Fa FTSENT
30852161Sbosticstructures will require that the path buffer be modified using the
30952161Sbosticinformation contained in that
31052161Sbostic.Fa FTSENT
31152161Sbosticstructure's
31252161Sbostic.Fa fts_pathlen
31352161Sbosticfield.
31452161SbosticAny such modifications should be undone before further calls to
31552161Sbostic.Fn fts_read
31652161Sbosticare attempted.
31752161SbosticThe
31852161Sbostic.Fa fts_name
31952161Sbosticfield is always
32052161Sbostic.Dv NULL Ns -terminated.
32148352Scael.Sh FTS_OPEN
32245617SbosticThe
32348352Scael.Fn fts_open
32445617Sbosticfunction takes a pointer to an array of character pointers naming one
32545617Sbosticor more paths which make up a logical file hierarchy to be traversed.
32648352ScaelThe array must be terminated by a
32748352Scael.Dv NULL
32848352Scaelpointer.
32948352Scael.Pp
33048352ScaelThere are
33148352Scaela number of options, at least one of which (either
33248352Scael.Dv FTS_LOGICAL
33348352Scaelor
33448352Scael.Dv FTS_PHYSICAL )
33548352Scaelmust be specified.
33645617SbosticThe options are selected by
33748352Scael.Em or Ns 'ing
33845617Sbosticthe following values:
33948352Scael.Bl -tag -width "FTS_PHYSICAL"
34048352Scael.It Dv FTS_LOGICAL
34145617SbosticThis option causes the
34248352Scael.Nm fts
34348352Scaelroutines to return
34448352Scael.Fa FTSENT
34548352Scaelstructures for the targets of symbolic links
34645617Sbosticinstead of the symbolic links themselves.
34748352ScaelIf this option is set, the only symbolic links for which
34848352Scael.Fa FTSENT
34948352Scaelstructures
35045617Sbosticare returned to the application are those referencing non-existent files.
35148352ScaelEither
35248352Scael.Dv FTS_LOGICAL
35348352Scaelor
35448352Scael.Dv FTS_PHYSICAL
35548352Scael.Em must
35645617Sbosticbe provided to the
35748352Scael.Fn fts_open
35845617Sbosticfunction.
35948352Scael.It Dv FTS_NOCHDIR
36045617SbosticAs a performance optimization, the
36148352Scael.Nm fts
36245617Sbosticfunctions change directories as they walk the file hierarchy.
36345617SbosticThis has the side-effect that an application cannot rely on being
36445617Sbosticin any particular directory during the traversal.
36548352ScaelThe
36648352Scael.Dv FTS_NOCHDIR
36748352Scaeloption turns off this optimization, and the
36848352Scael.Nm fts
36945617Sbosticfunctions will not change the current directory.
37045617SbosticNote that applications should not themselves change their current directory
37148352Scaeland try to access files unless
37248352Scael.Dv FTS_NOCHDIR
37348352Scaelis specified and absolute
37445617Sbosticpathnames were provided as arguments to
37548352Scael.Fn fts_open .
37648352Scael.It Dv FTS_NOSTAT
37748352ScaelBy default, returned
37848352Scael.Fa FTSENT
37948352Scaelstructures contain file characteristic
38045617Sbosticinformation (the
38148352Scael.Fa statb
38245617Sbosticfield) for each file visited.
38345617SbosticThis option relaxes that requirement as a performance optimization,
38445617Sbosticallowing the
38548352Scael.Nm fts
38645617Sbosticfunctions to set the
38748352Scael.Fa fts_info
38848352Scaelfield to
38948352Scael.Dv FTS_NSOK
39048352Scaeland leave the contents of the
39148352Scael.Fa statb
39245617Sbosticfield undefined.
39348352Scael.It Dv FTS_PHYSICAL
39445617SbosticThis option causes the
39548352Scael.Nm fts
39648352Scaelroutines to return
39748352Scael.Fa FTSENT
39848352Scaelstructures for symbolic links themselves instead
39945617Sbosticof the target files they point to.
40048352ScaelIf this option is set,
40148352Scael.Fa FTSENT
40248352Scaelstructures for all symbolic links in the
40345617Sbostichierarchy are returned to the application.
40448352ScaelEither
40548352Scael.Dv FTS_LOGICAL
40648352Scaelor
40748352Scael.Dv FTS_PHYSICAL
40848352Scael.Em must
40945617Sbosticbe provided to the
41048352Scael.Fn fts_open
41145617Sbosticfunction.
41248352Scael.It Dv FTS_SEEDOT
41345617SbosticBy default, unless they are specified as path arguments to
41448352Scael.Fn fts_open ,
41548352Scaelany files named
41648352Scael.Ql \&.
41752067Sbosticor
41848352Scael.Ql ..
419*52208Sbosticencountered in the file hierarchy are ignored.
42045617SbosticThis option causes the
42148352Scael.Nm fts
42248352Scaelroutines to return
42348352Scael.Fa FTSENT
42448352Scaelstructures for them.
42548352Scael.It Dv FTS_XDEV
42645617SbosticThis option prevents
42748352Scael.Nm fts
42845617Sbosticfrom descending into directories that have a different device number
42945617Sbosticthan the file from which the descent began.
43048352Scael.El
43148352Scael.Pp
43245617SbosticThe argument
43348352Scael.Fn compar
43445617Sbosticspecifies a user-defined function which may be used to order the traversal
43545617Sbosticof the hierarchy.
43648352ScaelIt
43748352Scaeltakes two pointers to pointers to
43848352Scael.Fa FTSENT
43948352Scaelstructures as arguments and
44045617Sbosticshould return a negative value, zero, or a positive value to indicate
44145617Sbosticif the file referenced by its first argument comes before, in any order
44245617Sbosticwith respect to, or after, the file referenced by its second argument.
44339801SbosticThe
44448352Scael.Fa fts_accpath ,
44548352Scael.Fa fts_path
44639801Sbosticand
44748352Scael.Fa fts_pathlen
44848352Scaelfields of the
44948352Scael.Fa FTSENT
45048352Scaelstructures may
45148352Scael.Em never
45245617Sbosticbe used in this comparison.
45347194SbosticIf the
45448352Scael.Fa fts_info
45548352Scaelfield is set to
45648352Scael.Dv FTS_NS
45748352Scaelor
45848352Scael.DV FTS_NSOK ,
45948352Scaelthe
46048352Scael.Fa fts_stab
46145617Sbosticfield may not either.
46245617SbosticIf the
46348352Scael.Fn compar
46448352Scaelargument is
46548352Scael.Dv NULL ,
46648352Scaelthe directory traversal order is unspecified except
46745617Sbosticfor the root paths which are traversed in the order listed in
46848352Scael.Fa path_argv .
46948352Scael.Sh FTS_READ
47039801SbosticThe
47148352Scael.Fn fts_read
47248352Scaelfunction returns a pointer to an
47348352Scael.Fa FTSENT
47448352Scaelstructure describing a file in
47545617Sbosticthe hierarchy.
47647194SbosticDirectories (that are readable and do not cause cycles) are visited at
47747194Sbosticleast twice, once in pre-order and once in post-order.
47845617SbosticAll other files are visited at least once.
47945617Sbostic(Hard links between directories that do not cause cycles or symbolic
48045617Sbosticlinks to symbolic links may cause files to be visited more than once,
48145617Sbosticor directories more than twice.)
48248352Scael.Pp
48339801SbosticIf all the members of the hierarchy have been returned,
48448352Scael.Fn fts_read
48548352Scaelreturns
48648352Scael.Dv NULL
48748352Scaeland sets the external variable
48848352Scael.Va errno
48939801Sbosticto 0.
49039801SbosticIf an error unrelated to a file in the hierarchy occurs,
49148352Scael.Fn fts_read
49248352Scaelreturns
49348352Scael.Dv NULL
49448352Scaeland sets
49548352Scael.Va errno
49645617Sbosticappropriately.
49748352ScaelIf an error related to a returned file occurs, a pointer to an
49848352Scael.Fa FTSENT
49945617Sbosticstructure is returned, and
50048352Scael.Va errno
50145617Sbosticmay or may not have been set (see
50248352Scael.Fa fts_info ) .
50348352Scael.Pp
50448352ScaelThe
50548352Scael.Fa FTSENT
50648352Scaelstructures returned by
50748352Scael.Fn fts_read
50845617Sbosticmay be overwritten after a call to
50948352Scael.Fn fts_close
51045617Sbosticon the same file hierarchy stream, or, after a call to
51148352Scael.Fn fts_read
51245617Sbosticon the same file hierarchy stream unless they represent a file of type
51345617Sbosticdirectory, in which case they will not be overwritten until after a call to
51448352Scael.Fn fts_read
51548352Scaelafter the
51648352Scael.Fa FTSENT
51748352Scaelstructure has been returned by the function
51848352Scael.Fn fts_read
51945617Sbosticin post-order.
52048352Scael.Sh FTS_CHILDREN
52145617SbosticThe
52248352Scael.Fn fts_children
52348352Scaelfunction returns a pointer to an
52448352Scael.Fa FTSENT
52552161Sbosticstructure describing the first entry in a NULL-terminated linked list of
52652161Sbosticthe files in the directory represented by the
52748352Scael.Fa FTSENT
52848352Scaelstructure most recently returned by
52948352Scael.Fn fts_read .
53045617SbosticThe list is linked through the
53148352Scael.Fa fts_link
53248352Scaelfield of the
53348352Scael.Fa FTSENT
53452161Sbosticstructure, and is ordered by the user-specified comparison function, if any.
53545617SbosticRepeated calls to
53648352Scael.Fn fts_children
53745617Sbosticwill recreate this linked list.
53848352Scael.Pp
53952161SbosticAs a special case, if
54052161Sbostic.Fn fts_read
54152161Sbostichas not yet been called for a hierarchy,
54252161Sbostic.Fn fts_children
54352161Sbosticwill return a pointer to the files in the logical directory specified to
54452161Sbostic.Fn fts_open ,
54552161Sbostici.e. the arguments specified to
54652161Sbostic.Fn fts_open .
54752161SbosticOtherwise, if the
54848352Scael.Fa FTSENT
54948352Scaelstructure most recently returned by
55048352Scael.Fn fts_read
55145617Sbosticis not a directory being visited in pre-order,
55245617Sbosticor the directory does not contain any files,
55348352Scael.Fn fts_children
55448352Scaelreturns
55548352Scael.Dv NULL
55648352Scaeland sets
55748352Scael.Va errno
55845617Sbosticto zero.
55939801SbosticIf an error occurs,
56048352Scael.Fn fts_children
56148352Scaelreturns
56248352Scael.Dv NULL
56348352Scaeland sets
56448352Scael.Va errno
56545617Sbosticappropriately.
56648352Scael.Pp
56748352ScaelThe
56848352Scael.Fa FTSENT
56948352Scaelstructures returned by
57048352Scael.Fn fts_children
57139801Sbosticmay be overwritten after a call to
57252075Sbostic.Fn fts_children ,
57348352Scael.Fn fts_close
57439801Sbosticor
57548352Scael.Fn fts_read
57645617Sbosticon the same file hierarchy stream.
57748352Scael.Sh FTS_SET
57845617SbosticThe function
57948352Scael.Fn fts_set
58039801Sbosticallows the user application to determine further processing for the
58139801Sbosticfile
58248352Scael.Fa f
58339801Sbosticof the stream
58448352Scael.Fa ftsp .
58548352ScaelThe
58648352Scael.Fn fts_set
58748352Scaelfunction
58848352Scaelreturns 0 on success, and \-1 if an error occurs.
58948352Scael.Em Option
59045617Sbosticmust be set to one of the following values:
59148352Scael.Bl -tag -width FTS_PHYSICAL
59248352Scael.It Dv FTS_AGAIN
59339801SbosticRe-visit the file; any file type may be re-visited.
59439801SbosticThe next call to
59548352Scael.Fn fts_read
59639801Sbosticwill return the referenced file.
59745617SbosticThe
59848352Scael.Fa fts_stat
59939801Sbosticand
60048352Scael.Fa fts_info
60139801Sbosticfields of the structure will be reinitialized at that time,
60245617Sbosticbut no other fields will have been changed.
60339801SbosticThis option is meaningful only for the most recently returned
60439801Sbosticfile from
60548352Scael.Fn fts_read .
60639801SbosticNormal use is for post-order directory visits, where it causes the
60739801Sbosticdirectory to be re-visited (in both pre and post-order) as well as all
60839801Sbosticof its descendants.
60948352Scael.It Dv FTS_FOLLOW
61039801SbosticThe referenced file must be a symbolic link.
61139801SbosticIf the referenced file is the one most recently returned by
61248352Scael.Fn fts_read ,
61339801Sbosticthe next call to
61448352Scael.Fn fts_read
61539801Sbosticreturns the file with the
61648352Scael.Fa fts_info
61739801Sbosticand
61848352Scael.Fa fts_statb
61939801Sbosticfields reinitialized to reflect the target of the symbolic link instead
62039801Sbosticof the symbolic link itself.
62139801SbosticIf the file is one of those most recently returned by
62248352Scael.Fn fts_children ,
62339801Sbosticthe
62448352Scael.Fa fts_info
62539801Sbosticand
62648352Scael.Fa fts_statb
62739801Sbosticfields of the structure, when returned by
62848352Scael.Fn fts_read ,
62939801Sbosticwill reflect the target of the symbolic link instead of the symbolic link
63039801Sbosticitself.
63147194SbosticIn either case, if the target of the symbolic link does not exist the
63247194Sbosticfields of the returned structure will be unchanged and the
63348352Scael.Fa fts_info
63448352Scaelfield will be set to
63548352Scael.Dv FTS_SLNONE .
63648352Scael.Pp
63747194SbosticIf the target of the link is a directory, the pre-order return, followed
63847194Sbosticby the return of all of its descendants, followed by a post-order return,
63947194Sbosticis done.
64048352Scael.It Dv FTS_SKIP
64139801SbosticNo descendants of this file are visited.
64245617SbosticThe file may be one of those most recently returned by either
64348352Scael.Fn fts_children
64445617Sbosticor
64548352Scael.Fn fts_read .
64648352Scael.El
64748352Scael.Sh FTS_CLOSE
64845617SbosticThe
64948352Scael.Fn fts_close
65045617Sbosticfunction closes a file hierarchy stream
65148352Scael.Fa ftsp
65245617Sbosticand restores the current directory to the directory from which
65348352Scael.Fn fts_open
65445617Sbosticwas called to open
65548352Scael.Fa ftsp .
65648352ScaelThe
65748352Scael.Fn fts_close
65848352Scaelfunction
65948352Scaelreturns 0 on success, and \-1 if an error occurs.
66048352Scael.Sh ERRORS
66148352ScaelThe function
66248352Scael.Fn fts_open
66339801Sbosticmay fail and set errno for any of the errors specified for the library
66445661Sbosticfunctions
66548352Scael.Xr open 2
66645661Sbosticand
66748352Scael.Xr malloc 3 .
66848352Scael.Pp
66948352ScaelThe function
67048352Scael.Fn fts_close
67139801Sbosticmay fail and set errno for any of the errors specified for the library
67245661Sbosticfunctions
67348352Scael.Xr chdir 2
67445661Sbosticand
67548352Scael.Xr close 2 .
67648352Scael.Pp
67748352ScaelThe functions
67850943Sbostic.Fn fts_read
67939801Sbosticand
68048352Scael.Fn fts_children
68139801Sbosticmay fail and set errno for any of the errors specified for the library
68245617Sbosticfunctions
68348352Scael.Xr chdir 2 ,
68448352Scael.Xr malloc 3 ,
68548352Scael.Xr opendir 3 ,
68648352Scael.Xr readdir 3
68739801Sbosticand
68848352Scael.Xr stat 2 .
68948352Scael.Sh SEE ALSO
69048352Scael.Xr find 1 ,
69148352Scael.Xr chdir 2 ,
69248352Scael.Xr stat 2 ,
69348352Scael.Xr qsort 3
69448352Scael.Sh STANDARDS
69539801SbosticThe
69648352Scael.Nm fts
69748352Scaelutility is expected to be a superset of the
69848352Scael.St -p1003.1-88
69947194Sbosticspecification.
700