xref: /csrg-svn/lib/libc/gen/fts.3 (revision 66814)
166731Sbostic.\" Copyright (c) 1989, 1991, 1993, 1994
261111Sbostic.\"	The Regents of the University of California.  All rights reserved.
339801Sbostic.\"
443571Strent.\" %sccs.include.redist.man%
539801Sbostic.\"
6*66814Sbostic.\"     @(#)fts.3	8.5 (Berkeley) 04/16/94
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 *
2352769Sbostic.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) */
8666731Sbostic	int fts_errno;			/* 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.
23348352Scael.It Fa fts_pointer
23445617SbosticThis field is provided for the use of the application program and is
23545617Sbosticnot modified by the
23648352Scael.Nm fts
23745617Sbosticfunctions.
23848352ScaelIt is initialized to
23948352Scael.Dv NULL .
24048352Scael.It Fa fts_parent
24148352ScaelA pointer to the
24248352Scael.Fa FTSENT
24348352Scaelstructure referencing the file in the hierarchy
24445617Sbosticimmediately above the current file, i.e. the directory of which this
24545617Sbosticfile is a member.
24645617SbosticA parent structure for the initial entry point is provided as well,
24745617Sbostichowever, only the
24848352Scael.Fa fts_level ,
24948352Scael.Fa fts_number
25045617Sbosticand
25148352Scael.Fa fts_pointer
25245617Sbosticfields are guaranteed to be initialized.
25348352Scael.It Fa fts_link
25452075SbosticUpon return from the
25552075Sbostic.Fn fts_children
25652075Sbosticfunction, the
25748352Scael.Fa fts_link
25852075Sbosticfield points to the next structure in the NULL-terminated linked list of
25952075Sbosticdirectory members.
26052075SbosticOtherwise, the contents of the
26152075Sbostic.Fa fts_link
26252075Sbosticfield are undefined.
26352075Sbostic.It Fa fts_cycle
26448352ScaelIf a directory causes a cycle in the hierarchy (see
26548352Scael.Dv FTS_DC ) ,
26648352Scaeleither because
26745617Sbosticof a hard link between two directories, or a symbolic link pointing to a
26845617Sbosticdirectory, the
26952075Sbostic.Fa fts_cycle
27048352Scaelfield of the structure will point to the
27148352Scael.Fa FTSENT
27252075Sbosticstructure in the hierarchy that references the same file as the current
27348352Scael.Fa FTSENT
27448352Scaelstructure.
27545617SbosticOtherwise, the contents of the
27652075Sbostic.Fa fts_cycle
27745617Sbosticfield are undefined.
27852227Sbostic.It Fa fts_statp
27952227SbosticA pointer to
28052227Sbostic.Xr stat 2
28139801Sbosticinformation for the file.
28248352Scael.El
28352161Sbostic.Pp
28452161SbosticA single buffer is used for all of the paths of all of the files in the
28552161Sbosticfile hierarchy.
28652161SbosticTherefore, the
28752161Sbostic.Fa fts_path
28852161Sbosticand
28952161Sbostic.Fa fts_accpath
29052161Sbosticfields are guaranteed to be
29152161Sbostic.Dv NULL Ns -terminated
29252161Sbostic.Em only
29352161Sbosticfor the file most recently returned by
29452161Sbostic.Fn fts_read .
29552161SbosticTo use these fields to reference any files represented by other
29652161Sbostic.Fa FTSENT
29752161Sbosticstructures will require that the path buffer be modified using the
29852161Sbosticinformation contained in that
29952161Sbostic.Fa FTSENT
30052161Sbosticstructure's
30152161Sbostic.Fa fts_pathlen
30252161Sbosticfield.
30352161SbosticAny such modifications should be undone before further calls to
30452161Sbostic.Fn fts_read
30552161Sbosticare attempted.
30652161SbosticThe
30752161Sbostic.Fa fts_name
30852161Sbosticfield is always
30952161Sbostic.Dv NULL Ns -terminated.
31048352Scael.Sh FTS_OPEN
31145617SbosticThe
31248352Scael.Fn fts_open
31345617Sbosticfunction takes a pointer to an array of character pointers naming one
31445617Sbosticor more paths which make up a logical file hierarchy to be traversed.
31548352ScaelThe array must be terminated by a
31648352Scael.Dv NULL
31748352Scaelpointer.
31848352Scael.Pp
31948352ScaelThere are
32048352Scaela number of options, at least one of which (either
32148352Scael.Dv FTS_LOGICAL
32248352Scaelor
32348352Scael.Dv FTS_PHYSICAL )
32448352Scaelmust be specified.
32545617SbosticThe options are selected by
32648352Scael.Em or Ns 'ing
32745617Sbosticthe following values:
32848352Scael.Bl -tag -width "FTS_PHYSICAL"
32952345Sbostic.It Dv FTS_COMFOLLOW
33052345SbosticThis option causes any symbolic link specified as a root path to be
33152345Sbosticfollowed immediately whether or not
33252345Sbostic.Dv FTS_LOGICAL
33352345Sbosticis also specified.
33448352Scael.It Dv FTS_LOGICAL
33545617SbosticThis option causes the
33648352Scael.Nm fts
33748352Scaelroutines to return
33848352Scael.Fa FTSENT
33948352Scaelstructures for the targets of symbolic links
34045617Sbosticinstead of the symbolic links themselves.
34148352ScaelIf this option is set, the only symbolic links for which
34248352Scael.Fa FTSENT
34348352Scaelstructures
34445617Sbosticare returned to the application are those referencing non-existent files.
34548352ScaelEither
34648352Scael.Dv FTS_LOGICAL
34748352Scaelor
34848352Scael.Dv FTS_PHYSICAL
34948352Scael.Em must
35045617Sbosticbe provided to the
35148352Scael.Fn fts_open
35245617Sbosticfunction.
35348352Scael.It Dv FTS_NOCHDIR
35445617SbosticAs a performance optimization, the
35548352Scael.Nm fts
35645617Sbosticfunctions change directories as they walk the file hierarchy.
35745617SbosticThis has the side-effect that an application cannot rely on being
35845617Sbosticin any particular directory during the traversal.
35948352ScaelThe
36048352Scael.Dv FTS_NOCHDIR
36148352Scaeloption turns off this optimization, and the
36248352Scael.Nm fts
36345617Sbosticfunctions will not change the current directory.
36445617SbosticNote that applications should not themselves change their current directory
36548352Scaeland try to access files unless
36648352Scael.Dv FTS_NOCHDIR
36748352Scaelis specified and absolute
36845617Sbosticpathnames were provided as arguments to
36948352Scael.Fn fts_open .
37048352Scael.It Dv FTS_NOSTAT
37148352ScaelBy default, returned
37248352Scael.Fa FTSENT
37352227Sbosticstructures reference file characteristic information (the
37452227Sbostic.Fa statp
37545617Sbosticfield) for each file visited.
37645617SbosticThis option relaxes that requirement as a performance optimization,
37745617Sbosticallowing the
37848352Scael.Nm fts
37945617Sbosticfunctions to set the
38048352Scael.Fa fts_info
38148352Scaelfield to
38248352Scael.Dv FTS_NSOK
38348352Scaeland leave the contents of the
38452227Sbostic.Fa statp
38545617Sbosticfield undefined.
38648352Scael.It Dv FTS_PHYSICAL
38745617SbosticThis option causes the
38848352Scael.Nm fts
38948352Scaelroutines to return
39048352Scael.Fa FTSENT
39148352Scaelstructures for symbolic links themselves instead
39245617Sbosticof the target files they point to.
39348352ScaelIf this option is set,
39448352Scael.Fa FTSENT
39548352Scaelstructures for all symbolic links in the
39645617Sbostichierarchy are returned to the application.
39748352ScaelEither
39848352Scael.Dv FTS_LOGICAL
39948352Scaelor
40048352Scael.Dv FTS_PHYSICAL
40148352Scael.Em must
40245617Sbosticbe provided to the
40348352Scael.Fn fts_open
40445617Sbosticfunction.
40548352Scael.It Dv FTS_SEEDOT
40645617SbosticBy default, unless they are specified as path arguments to
40748352Scael.Fn fts_open ,
40848352Scaelany files named
40948352Scael.Ql \&.
41052067Sbosticor
41148352Scael.Ql ..
41252208Sbosticencountered in the file hierarchy are ignored.
41345617SbosticThis option causes the
41448352Scael.Nm fts
41548352Scaelroutines to return
41648352Scael.Fa FTSENT
41748352Scaelstructures for them.
41848352Scael.It Dv FTS_XDEV
41945617SbosticThis option prevents
42048352Scael.Nm fts
42145617Sbosticfrom descending into directories that have a different device number
42245617Sbosticthan the file from which the descent began.
42348352Scael.El
42448352Scael.Pp
42545617SbosticThe argument
42648352Scael.Fn compar
42745617Sbosticspecifies a user-defined function which may be used to order the traversal
42845617Sbosticof the hierarchy.
42948352ScaelIt
43048352Scaeltakes two pointers to pointers to
43148352Scael.Fa FTSENT
43248352Scaelstructures as arguments and
43345617Sbosticshould return a negative value, zero, or a positive value to indicate
43445617Sbosticif the file referenced by its first argument comes before, in any order
43545617Sbosticwith respect to, or after, the file referenced by its second argument.
43639801SbosticThe
43748352Scael.Fa fts_accpath ,
43848352Scael.Fa fts_path
43939801Sbosticand
44048352Scael.Fa fts_pathlen
44148352Scaelfields of the
44248352Scael.Fa FTSENT
44348352Scaelstructures may
44448352Scael.Em never
44545617Sbosticbe used in this comparison.
44647194SbosticIf the
44748352Scael.Fa fts_info
44848352Scaelfield is set to
44948352Scael.Dv FTS_NS
45048352Scaelor
45152345Sbostic.Dv FTS_NSOK ,
45248352Scaelthe
45352227Sbostic.Fa fts_statp
45445617Sbosticfield may not either.
45545617SbosticIf the
45648352Scael.Fn compar
45748352Scaelargument is
45848352Scael.Dv NULL ,
45952345Sbosticthe directory traversal order is in the order listed in
46052345Sbostic.Fa path_argv
46152345Sbosticfor the root paths, and in the order listed in the directory for
46252345Sbosticeverything else.
46348352Scael.Sh FTS_READ
46439801SbosticThe
46548352Scael.Fn fts_read
46648352Scaelfunction returns a pointer to an
46748352Scael.Fa FTSENT
46848352Scaelstructure describing a file in
46945617Sbosticthe hierarchy.
47047194SbosticDirectories (that are readable and do not cause cycles) are visited at
47147194Sbosticleast twice, once in pre-order and once in post-order.
47245617SbosticAll other files are visited at least once.
47345617Sbostic(Hard links between directories that do not cause cycles or symbolic
47445617Sbosticlinks to symbolic links may cause files to be visited more than once,
47545617Sbosticor directories more than twice.)
47648352Scael.Pp
47739801SbosticIf all the members of the hierarchy have been returned,
47848352Scael.Fn fts_read
47948352Scaelreturns
48048352Scael.Dv NULL
48148352Scaeland sets the external variable
48248352Scael.Va errno
48339801Sbosticto 0.
48439801SbosticIf an error unrelated to a file in the hierarchy occurs,
48548352Scael.Fn fts_read
48648352Scaelreturns
48748352Scael.Dv NULL
48848352Scaeland sets
48948352Scael.Va errno
49045617Sbosticappropriately.
49148352ScaelIf an error related to a returned file occurs, a pointer to an
49248352Scael.Fa FTSENT
49345617Sbosticstructure is returned, and
49448352Scael.Va errno
49545617Sbosticmay or may not have been set (see
49648352Scael.Fa fts_info ) .
49748352Scael.Pp
49848352ScaelThe
49948352Scael.Fa FTSENT
50048352Scaelstructures returned by
50148352Scael.Fn fts_read
50245617Sbosticmay be overwritten after a call to
50348352Scael.Fn fts_close
50445617Sbosticon the same file hierarchy stream, or, after a call to
50548352Scael.Fn fts_read
50645617Sbosticon the same file hierarchy stream unless they represent a file of type
50745617Sbosticdirectory, in which case they will not be overwritten until after a call to
50848352Scael.Fn fts_read
50948352Scaelafter the
51048352Scael.Fa FTSENT
51148352Scaelstructure has been returned by the function
51248352Scael.Fn fts_read
51345617Sbosticin post-order.
51448352Scael.Sh FTS_CHILDREN
51545617SbosticThe
51648352Scael.Fn fts_children
51748352Scaelfunction returns a pointer to an
51848352Scael.Fa FTSENT
51952161Sbosticstructure describing the first entry in a NULL-terminated linked list of
52052161Sbosticthe files in the directory represented by the
52148352Scael.Fa FTSENT
52248352Scaelstructure most recently returned by
52348352Scael.Fn fts_read .
52445617SbosticThe list is linked through the
52548352Scael.Fa fts_link
52648352Scaelfield of the
52748352Scael.Fa FTSENT
52852161Sbosticstructure, and is ordered by the user-specified comparison function, if any.
52945617SbosticRepeated calls to
53048352Scael.Fn fts_children
53145617Sbosticwill recreate this linked list.
53248352Scael.Pp
53352161SbosticAs a special case, if
53452161Sbostic.Fn fts_read
53552161Sbostichas not yet been called for a hierarchy,
53652161Sbostic.Fn fts_children
53752161Sbosticwill return a pointer to the files in the logical directory specified to
53852161Sbostic.Fn fts_open ,
53952161Sbostici.e. the arguments specified to
54052161Sbostic.Fn fts_open .
54152161SbosticOtherwise, if the
54248352Scael.Fa FTSENT
54348352Scaelstructure most recently returned by
54448352Scael.Fn fts_read
54545617Sbosticis not a directory being visited in pre-order,
54645617Sbosticor the directory does not contain any files,
54748352Scael.Fn fts_children
54848352Scaelreturns
54948352Scael.Dv NULL
55048352Scaeland sets
55148352Scael.Va errno
55245617Sbosticto zero.
55339801SbosticIf an error occurs,
55448352Scael.Fn fts_children
55548352Scaelreturns
55648352Scael.Dv NULL
55748352Scaeland sets
55848352Scael.Va errno
55945617Sbosticappropriately.
56048352Scael.Pp
56148352ScaelThe
56248352Scael.Fa FTSENT
56348352Scaelstructures returned by
56448352Scael.Fn fts_children
56539801Sbosticmay be overwritten after a call to
56652075Sbostic.Fn fts_children ,
56748352Scael.Fn fts_close
56839801Sbosticor
56948352Scael.Fn fts_read
57045617Sbosticon the same file hierarchy stream.
57152769Sbostic.Pp
57252769Sbostic.Em Option
57352769Sbosticmay be set to the following value:
57452769Sbostic.Bl -tag -width FTS_NAMEONLY
57552769Sbostic.It Dv FTS_NAMEONLY
57652769SbosticOnly the names of the files are needed.
57752769SbosticThe contents of all the fields in the returned linked list of structures
57852769Sbosticare undefined with the exception of the
57952769Sbostic.Fa fts_name
58052769Sbosticand
58152769Sbostic.Fa fts_namelen
58252769Sbosticfields.
58352769Sbostic.El
58448352Scael.Sh FTS_SET
58545617SbosticThe function
58648352Scael.Fn fts_set
58739801Sbosticallows the user application to determine further processing for the
58839801Sbosticfile
58948352Scael.Fa f
59039801Sbosticof the stream
59148352Scael.Fa ftsp .
59248352ScaelThe
59348352Scael.Fn fts_set
59448352Scaelfunction
59548352Scaelreturns 0 on success, and \-1 if an error occurs.
59648352Scael.Em Option
59745617Sbosticmust be set to one of the following values:
59848352Scael.Bl -tag -width FTS_PHYSICAL
59948352Scael.It Dv FTS_AGAIN
60039801SbosticRe-visit the file; any file type may be re-visited.
60139801SbosticThe next call to
60248352Scael.Fn fts_read
60339801Sbosticwill return the referenced file.
60445617SbosticThe
60548352Scael.Fa fts_stat
60639801Sbosticand
60748352Scael.Fa fts_info
60839801Sbosticfields of the structure will be reinitialized at that time,
60945617Sbosticbut no other fields will have been changed.
61039801SbosticThis option is meaningful only for the most recently returned
61139801Sbosticfile from
61248352Scael.Fn fts_read .
61339801SbosticNormal use is for post-order directory visits, where it causes the
61439801Sbosticdirectory to be re-visited (in both pre and post-order) as well as all
61539801Sbosticof its descendants.
61648352Scael.It Dv FTS_FOLLOW
61739801SbosticThe referenced file must be a symbolic link.
61839801SbosticIf the referenced file is the one most recently returned by
61948352Scael.Fn fts_read ,
62039801Sbosticthe next call to
62148352Scael.Fn fts_read
62239801Sbosticreturns the file with the
62348352Scael.Fa fts_info
62439801Sbosticand
62552227Sbostic.Fa fts_statp
62639801Sbosticfields reinitialized to reflect the target of the symbolic link instead
62739801Sbosticof the symbolic link itself.
62839801SbosticIf the file is one of those most recently returned by
62948352Scael.Fn fts_children ,
63039801Sbosticthe
63148352Scael.Fa fts_info
63239801Sbosticand
63352227Sbostic.Fa fts_statp
63439801Sbosticfields of the structure, when returned by
63548352Scael.Fn fts_read ,
63639801Sbosticwill reflect the target of the symbolic link instead of the symbolic link
63739801Sbosticitself.
63847194SbosticIn either case, if the target of the symbolic link does not exist the
63947194Sbosticfields of the returned structure will be unchanged and the
64048352Scael.Fa fts_info
64148352Scaelfield will be set to
64248352Scael.Dv FTS_SLNONE .
64348352Scael.Pp
64447194SbosticIf the target of the link is a directory, the pre-order return, followed
64547194Sbosticby the return of all of its descendants, followed by a post-order return,
64647194Sbosticis done.
64748352Scael.It Dv FTS_SKIP
64839801SbosticNo descendants of this file are visited.
64945617SbosticThe file may be one of those most recently returned by either
65048352Scael.Fn fts_children
65145617Sbosticor
65248352Scael.Fn fts_read .
65348352Scael.El
65448352Scael.Sh FTS_CLOSE
65545617SbosticThe
65648352Scael.Fn fts_close
65745617Sbosticfunction closes a file hierarchy stream
65848352Scael.Fa ftsp
65945617Sbosticand restores the current directory to the directory from which
66048352Scael.Fn fts_open
66145617Sbosticwas called to open
66248352Scael.Fa ftsp .
66348352ScaelThe
66448352Scael.Fn fts_close
66548352Scaelfunction
66648352Scaelreturns 0 on success, and \-1 if an error occurs.
66748352Scael.Sh ERRORS
66848352ScaelThe function
66948352Scael.Fn fts_open
67052769Sbosticmay fail and set
67152769Sbostic.Va errno
67252769Sbosticfor any of the errors specified for the library functions
67348352Scael.Xr open 2
67445661Sbosticand
67548352Scael.Xr malloc 3 .
67648352Scael.Pp
67748352ScaelThe function
67848352Scael.Fn fts_close
67952769Sbosticmay fail and set
68052769Sbostic.Va errno
68152769Sbosticfor any of the errors specified for the library functions
68248352Scael.Xr chdir 2
68345661Sbosticand
68448352Scael.Xr close 2 .
68548352Scael.Pp
68648352ScaelThe functions
68750943Sbostic.Fn fts_read
68839801Sbosticand
68948352Scael.Fn fts_children
69052769Sbosticmay fail and set
69152769Sbostic.Va errno
69252769Sbosticfor any of the errors specified for the library functions
69348352Scael.Xr chdir 2 ,
69448352Scael.Xr malloc 3 ,
69548352Scael.Xr opendir 3 ,
69648352Scael.Xr readdir 3
69739801Sbosticand
69848352Scael.Xr stat 2 .
69952769Sbostic.Pp
70052769SbosticIn addition,
70152769Sbostic.Fn fts_children ,
70252769Sbostic.Fn fts_open
70352769Sbosticand
70452769Sbostic.Fn fts_set
70552769Sbosticmay fail and set
70652769Sbostic.Va errno
70752769Sbosticas follows:
70852769Sbostic.Bl -tag -width Er
70952769Sbostic.It Bq Er EINVAL
71052769SbosticThe options were invalid.
711*66814Sbostic.El
71248352Scael.Sh SEE ALSO
71348352Scael.Xr find 1 ,
71448352Scael.Xr chdir 2 ,
71548352Scael.Xr stat 2 ,
71648352Scael.Xr qsort 3
71748352Scael.Sh STANDARDS
71839801SbosticThe
71948352Scael.Nm fts
72066114Sbosticutility is expected to be included in a future
72148352Scael.St -p1003.1-88
72264896Sbosticrevision.
723