]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/fts.3
(no commit message)
[thirdparty/man-pages.git] / man3 / fts.3
CommitLineData
fea681da
MK
1.\" $NetBSD: fts.3,v 1.13.2.1 1997/11/14 02:09:32 mrg Exp $
2.\"
3.\" Copyright (c) 1989, 1991, 1993, 1994
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)fts.3 8.5 (Berkeley) 4/16/94
35.\"
3233d665
MK
36.\" 2007-12-02, mtk, Converted from mdoc to man macros
37.\"
38.TH FTS 3 2007-12-02 "Linux" "Linux Programmer's Manual"
39.SH NAME
40fts, fts_open, fts_read, fts_children, fts_set, fts_close \- \
41traverse a file hierarchy
42.SH SYNOPSIS
43.nf
44.B #include <sys/types.h>
45.B #include <sys/stat.h>
46.B #include <fts.h>
47.sp
48.BI "FTS *fts_open(char * const *" path_argv ", int " options ", "
49.IB " int (*compar)(const FTSENT **, const FTSENT **)" );
50.sp
51.BI "FTSENT *fts_read(FTS *" ftsp );
52.sp
53.BI "FTSENT *fts_children(FTS *" ftsp ", int " options );
54.sp
55.BI "int fts_set(FTS *" ftsp ", FTSENT *" f ", int " options );
56.sp
57.BI "int fts_close(FTS *" ftsp );
58.fi
59.SH DESCRIPTION
fea681da 60The
3233d665 61fts functions are provided for traversing
fea681da
MK
62file hierarchies.
63A simple overview is that the
3233d665 64.BR fts_open ()
fea681da
MK
65function returns a ``handle'' on a file hierarchy, which is then supplied to
66the other
3233d665 67fts functions.
fea681da 68The function
3233d665 69.BR fts_read ()
fea681da
MK
70returns a pointer to a structure describing one of the files in the file
71hierarchy.
72The function
3233d665 73.BR fts_children ()
fea681da
MK
74returns a pointer to a linked list of structures, each of which describes
75one of the files contained in a directory in the hierarchy.
76In general, directories are visited two distinguishable times; in pre-order
77(before any of their descendants are visited) and in post-order (after all
78of their descendants have been visited).
79Files are visited once.
80It is possible to walk the hierarchy ``logically'' (ignoring symbolic links)
81or physically (visiting symbolic links), order the walk of the hierarchy or
82prune and/or re-visit portions of the hierarchy.
3233d665 83.sp
fea681da 84Two structures are defined (and typedef'd) in the include file
3233d665 85.IR <fts.h> .
fea681da 86The first is
3233d665 87.IR FTS ,
fea681da
MK
88the structure that represents the file hierarchy itself.
89The second is
3233d665 90.IR FTSENT ,
fea681da
MK
91the structure that represents a file in the file
92hierarchy.
93Normally, an
3233d665 94.I FTSENT
fea681da
MK
95structure is returned for every file in the file
96hierarchy.
3233d665
MK
97In this manual page, "file" and
98"FTSENT structure"
99are generally interchangeable.
fea681da 100The
3233d665 101.I FTSENT
fea681da
MK
102structure contains at least the following fields, which are
103described in greater detail below:
3233d665
MK
104.in +0.25i
105.nf
106
fea681da 107typedef struct _ftsent {
3233d665
MK
108 u_short fts_info; /* flags for FTSENT structure */
109 char *fts_accpath; /* access path */
110 char *fts_path; /* root path */
111 short fts_pathlen; /* strlen(fts_path) */
112 char *fts_name; /* filename */
113 short fts_namelen; /* strlen(fts_name) */
114 short fts_level; /* depth (\-1 to N) */
115 int fts_errno; /* file errno */
116 long fts_number; /* local numeric value */
117 void *fts_pointer; /* local address value */
118 struct ftsent *fts_parent; /* parent directory */
119 struct ftsent *fts_link; /* next file structure */
120 struct ftsent *fts_cycle; /* cycle structure */
121 struct stat *fts_statp; /* stat(2) information */
fea681da 122} FTSENT;
3233d665
MK
123.fi
124.in
125.sp
fea681da 126These fields are defined as follows:
3233d665
MK
127.\" .Bl -tag -width "fts_namelen"
128.TP 12
129.IR fts_info
fea681da 130One of the following flags describing the returned
3233d665 131.I FTSENT
fea681da
MK
132structure and
133the file it represents.
134With the exception of directories without errors
3233d665 135.RB ( FTS_D ),
fea681da
MK
136all of these
137entries are terminal, that is, they will not be revisited, nor will any
138of their descendants be visited.
3233d665
MK
139.\" .Bl -tag -width FTS_DEFAULT
140.RS 12
141.TP 12
142.BR FTS_D
fea681da 143A directory being visited in pre-order.
3233d665
MK
144.TP
145.BR FTS_DC
fea681da
MK
146A directory that causes a cycle in the tree.
147(The
3233d665 148.I fts_cycle
fea681da 149field of the
3233d665 150.I FTSENT
fea681da 151structure will be filled in as well.)
3233d665
MK
152.TP
153.BR FTS_DEFAULT
fea681da 154Any
3233d665 155.I FTSENT
fea681da
MK
156structure that represents a file type not explicitly described
157by one of the other
3233d665 158.I fts_info
fea681da 159values.
3233d665
MK
160.TP
161.BR FTS_DNR
fea681da
MK
162A directory which cannot be read.
163This is an error return, and the
3233d665 164.I fts_errno
fea681da 165field will be set to indicate what caused the error.
3233d665
MK
166.TP
167.BR FTS_DOT
fea681da 168A file named
3233d665 169"."
fea681da 170or
3233d665 171".."
2c5f1089 172which was not specified as a filename to
3233d665 173.BR fts_open ()
fea681da 174(see
3233d665
MK
175.BR FTS_SEEDOT ) .
176.TP
177.BR FTS_DP
fea681da
MK
178A directory being visited in post-order.
179The contents of the
3233d665 180.I FTSENT
fea681da 181structure will be unchanged from when
75b94dc3 182it was returned in pre-order, that is, with the
3233d665 183.I fts_info
fea681da 184field set to
3233d665
MK
185.BR FTS_D .
186.TP
187.BR FTS_ERR
fea681da 188This is an error return, and the
3233d665 189.I fts_errno
fea681da 190field will be set to indicate what caused the error.
3233d665
MK
191.TP
192.BR FTS_F
fea681da 193A regular file.
3233d665
MK
194.TP
195.BR FTS_NS
fea681da 196A file for which no
3233d665 197.BR stat (2)
fea681da
MK
198information was available.
199The contents of the
3233d665 200.I fts_statp
fea681da
MK
201field are undefined.
202This is an error return, and the
3233d665 203.I fts_errno
fea681da 204field will be set to indicate what caused the error.
3233d665
MK
205.TP
206.BR FTS_NSOK
fea681da 207A file for which no
3233d665 208.BR stat (2)
fea681da
MK
209information was requested.
210The contents of the
3233d665 211.I fts_statp
fea681da 212field are undefined.
3233d665
MK
213.TP
214.BR FTS_SL
fea681da 215A symbolic link.
3233d665
MK
216.TP
217.BR FTS_SLNONE
fea681da
MK
218A symbolic link with a non-existent target.
219The contents of the
3233d665 220.I fts_statp
fea681da
MK
221field reference the file characteristic information for the symbolic link
222itself.
3233d665
MK
223.\" .El
224.RE
225.TP
226.IR fts_accpath
fea681da 227A path for accessing the file from the current directory.
3233d665
MK
228.TP
229.IR fts_path
fea681da
MK
230The path for the file relative to the root of the traversal.
231This path contains the path specified to
3233d665 232.BR fts_open ()
fea681da 233as a prefix.
3233d665
MK
234.TP
235.IR fts_pathlen
fea681da 236The length of the string referenced by
3233d665
MK
237.IR fts_path .
238.TP
239.IR fts_name
fea681da 240The name of the file.
3233d665
MK
241.TP
242.IR fts_namelen
fea681da 243The length of the string referenced by
3233d665
MK
244.IR fts_name .
245.TP
246.IR fts_level
fea681da
MK
247The depth of the traversal, numbered from \-1 to N, where this file
248was found.
249The
3233d665 250.I FTSENT
fea681da
MK
251structure representing the parent of the starting point (or root)
252of the traversal is numbered \-1, and the
3233d665 253.I FTSENT
fea681da
MK
254structure for the root
255itself is numbered 0.
3233d665
MK
256.TP
257.IR fts_errno
fea681da 258Upon return of a
3233d665 259.I FTSENT
fea681da 260structure from the
3233d665 261.BR fts_children ()
fea681da 262or
3233d665 263.BR fts_read ()
fea681da 264functions, with its
3233d665 265.I fts_info
c13182ef 266field set to
3233d665
MK
267.BR FTS_DNR ,
268.BR FTS_ERR
fea681da 269or
3233d665 270.BR FTS_NS ,
fea681da 271the
3233d665 272.I fts_errno
fea681da 273field contains the value of the external variable
3233d665 274.I errno
fea681da
MK
275specifying the cause of the error.
276Otherwise, the contents of the
3233d665 277.I fts_errno
fea681da 278field are undefined.
3233d665
MK
279.TP
280.IR fts_number
fea681da
MK
281This field is provided for the use of the application program and is
282not modified by the
3233d665 283fts functions.
fea681da 284It is initialized to 0.
3233d665
MK
285.TP
286.IR fts_pointer
fea681da
MK
287This field is provided for the use of the application program and is
288not modified by the
3233d665 289fts functions.
fea681da 290It is initialized to
3233d665
MK
291NULL.
292.TP
293.IR fts_parent
fea681da 294A pointer to the
3233d665 295.I FTSENT
fea681da 296structure referencing the file in the hierarchy
75b94dc3 297immediately above the current file, that is, the directory of which this
fea681da
MK
298file is a member.
299A parent structure for the initial entry point is provided as well,
300however, only the
3233d665
MK
301.IR fts_level ,
302.I fts_number
fea681da 303and
3233d665 304.I fts_pointer
fea681da 305fields are guaranteed to be initialized.
3233d665
MK
306.TP
307.IR fts_link
fea681da 308Upon return from the
3233d665 309.BR fts_children ()
fea681da 310function, the
3233d665 311.I fts_link
fea681da
MK
312field points to the next structure in the NULL-terminated linked list of
313directory members.
314Otherwise, the contents of the
3233d665 315.I fts_link
fea681da 316field are undefined.
3233d665
MK
317.TP
318.IR fts_cycle
fea681da 319If a directory causes a cycle in the hierarchy (see
3233d665 320.BR FTS_DC ) ,
fea681da
MK
321either because
322of a hard link between two directories, or a symbolic link pointing to a
323directory, the
3233d665 324.I fts_cycle
fea681da 325field of the structure will point to the
3233d665 326.I FTSENT
fea681da 327structure in the hierarchy that references the same file as the current
3233d665 328.I FTSENT
fea681da
MK
329structure.
330Otherwise, the contents of the
3233d665 331.I fts_cycle
fea681da 332field are undefined.
3233d665
MK
333.TP
334.IR fts_statp
fea681da 335A pointer to
3233d665 336.BR stat (2)
fea681da 337information for the file.
3233d665
MK
338.\" .El
339.PP
fea681da
MK
340A single buffer is used for all of the paths of all of the files in the
341file hierarchy.
342Therefore, the
3233d665 343.I fts_path
fea681da 344and
3233d665 345.I fts_accpath
fea681da 346fields are guaranteed to be
3233d665
MK
347NULL-terminated
348.I only
fea681da 349for the file most recently returned by
3233d665 350.BR fts_read ().
fea681da 351To use these fields to reference any files represented by other
3233d665 352.I FTSENT
fea681da
MK
353structures will require that the path buffer be modified using the
354information contained in that
3233d665 355.I FTSENT
fea681da 356structure's
3233d665 357.I fts_pathlen
fea681da
MK
358field.
359Any such modifications should be undone before further calls to
3233d665 360.BR fts_read ()
fea681da
MK
361are attempted.
362The
3233d665 363.I fts_name
fea681da 364field is always
3233d665
MK
365NULL-terminated.
366.SS fts_open()
fea681da 367The
3233d665 368.BR fts_open ()
fea681da
MK
369function takes a pointer to an array of character pointers naming one
370or more paths which make up a logical file hierarchy to be traversed.
371The array must be terminated by a
3233d665 372NULL
fea681da 373pointer.
3233d665 374.sp
fea681da
MK
375There are
376a number of options, at least one of which (either
3233d665 377.BR FTS_LOGICAL
fea681da 378or
3233d665 379.BR FTS_PHYSICAL )
fea681da
MK
380must be specified.
381The options are selected by
3233d665 382.IR or ing
fea681da 383the following values:
3233d665
MK
384.\" .Bl -tag -width "FTS_PHYSICAL"
385.TP 13
386.BR FTS_COMFOLLOW
fea681da
MK
387This option causes any symbolic link specified as a root path to be
388followed immediately whether or not
3233d665 389.BR FTS_LOGICAL
fea681da 390is also specified.
3233d665
MK
391.TP
392.BR FTS_LOGICAL
fea681da 393This option causes the
3233d665
MK
394fts routines to return
395.I FTSENT
fea681da
MK
396structures for the targets of symbolic links
397instead of the symbolic links themselves.
398If this option is set, the only symbolic links for which
3233d665 399.I FTSENT
fea681da
MK
400structures
401are returned to the application are those referencing non-existent files.
402Either
3233d665 403.BR FTS_LOGICAL
fea681da 404or
3233d665
MK
405.BR FTS_PHYSICAL
406.I must
fea681da 407be provided to the
3233d665 408.BR fts_open ()
fea681da 409function.
3233d665
MK
410.TP
411.BR FTS_NOCHDIR
fea681da 412As a performance optimization, the
3233d665 413fts functions change directories as they walk the file hierarchy.
fea681da
MK
414This has the side-effect that an application cannot rely on being
415in any particular directory during the traversal.
416The
3233d665 417.BR FTS_NOCHDIR
fea681da 418option turns off this optimization, and the
3233d665 419fts functions will not change the current directory.
fea681da
MK
420Note that applications should not themselves change their current directory
421and try to access files unless
3233d665 422.BR FTS_NOCHDIR
fea681da
MK
423is specified and absolute
424pathnames were provided as arguments to
3233d665
MK
425.BR fts_open ().
426.TP
427.BR FTS_NOSTAT
fea681da 428By default, returned
3233d665 429.I FTSENT
fea681da 430structures reference file characteristic information (the
3233d665 431.I statp
fea681da
MK
432field) for each file visited.
433This option relaxes that requirement as a performance optimization,
434allowing the
3233d665
MK
435fts functions to set the
436.I fts_info
fea681da 437field to
3233d665 438.BR FTS_NSOK
fea681da 439and leave the contents of the
3233d665 440.I statp
fea681da 441field undefined.
3233d665
MK
442.TP
443.BR FTS_PHYSICAL
fea681da 444This option causes the
3233d665
MK
445fts routines to return
446.I FTSENT
fea681da
MK
447structures for symbolic links themselves instead
448of the target files they point to.
449If this option is set,
3233d665 450.I FTSENT
fea681da
MK
451structures for all symbolic links in the
452hierarchy are returned to the application.
453Either
3233d665 454.BR FTS_LOGICAL
fea681da 455or
3233d665
MK
456.BR FTS_PHYSICAL
457.I must
fea681da 458be provided to the
3233d665 459.BR fts_open ()
fea681da 460function.
3233d665
MK
461.TP
462.BR FTS_SEEDOT
fea681da 463By default, unless they are specified as path arguments to
3233d665 464.BR fts_open (),
fea681da 465any files named
3233d665 466"."
fea681da 467or
3233d665 468".."
fea681da
MK
469encountered in the file hierarchy are ignored.
470This option causes the
3233d665
MK
471fts routines to return
472.I FTSENT
fea681da 473structures for them.
3233d665
MK
474.TP
475.BR FTS_XDEV
fea681da 476This option prevents
3233d665 477fts from descending into directories that have a different device number
fea681da 478than the file from which the descent began.
3233d665
MK
479.\" .El
480.sp
fea681da 481The argument
3233d665 482.BR compar ()
fea681da
MK
483specifies a user-defined function which may be used to order the traversal
484of the hierarchy.
485It
486takes two pointers to pointers to
3233d665 487.I FTSENT
fea681da
MK
488structures as arguments and
489should return a negative value, zero, or a positive value to indicate
490if the file referenced by its first argument comes before, in any order
491with respect to, or after, the file referenced by its second argument.
492The
3233d665
MK
493.IR fts_accpath ,
494.I fts_path
fea681da 495and
3233d665 496.I fts_pathlen
fea681da 497fields of the
3233d665 498.I FTSENT
fea681da 499structures may
3233d665 500.I never
fea681da 501be used in this comparison.
c13182ef 502If the
3233d665 503.I fts_info
fea681da 504field is set to
3233d665 505.BR FTS_NS
fea681da 506or
3233d665 507.BR FTS_NSOK ,
fea681da 508the
3233d665 509.I fts_statp
fea681da
MK
510field may not either.
511If the
3233d665 512.BR compar ()
fea681da 513argument is
3233d665 514NULL,
fea681da 515the directory traversal order is in the order listed in
3233d665 516.I path_argv
fea681da
MK
517for the root paths, and in the order listed in the directory for
518everything else.
3233d665 519.SS fts_read()
fea681da 520The
3233d665 521.BR fts_read ()
fea681da 522function returns a pointer to an
3233d665 523.I FTSENT
fea681da
MK
524structure describing a file in
525the hierarchy.
526Directories (that are readable and do not cause cycles) are visited at
527least twice, once in pre-order and once in post-order.
528All other files are visited at least once.
529(Hard links between directories that do not cause cycles or symbolic
530links to symbolic links may cause files to be visited more than once,
531or directories more than twice.)
3233d665 532.sp
fea681da 533If all the members of the hierarchy have been returned,
3233d665 534.BR fts_read ()
fea681da 535returns
3233d665 536NULL
fea681da 537and sets the external variable
3233d665 538.I errno
fea681da
MK
539to 0.
540If an error unrelated to a file in the hierarchy occurs,
3233d665 541.BR fts_read ()
fea681da 542returns
3233d665 543NULL
fea681da 544and sets
3233d665 545.I errno
fea681da
MK
546appropriately.
547If an error related to a returned file occurs, a pointer to an
3233d665 548.I FTSENT
fea681da 549structure is returned, and
3233d665 550.I errno
fea681da 551may or may not have been set (see
3233d665
MK
552.IR fts_info ).
553.sp
fea681da 554The
3233d665 555.I FTSENT
fea681da 556structures returned by
3233d665 557.BR fts_read ()
fea681da 558may be overwritten after a call to
3233d665 559.BR fts_close ()
fea681da 560on the same file hierarchy stream, or, after a call to
3233d665 561.BR fts_read ()
fea681da
MK
562on the same file hierarchy stream unless they represent a file of type
563directory, in which case they will not be overwritten until after a call to
3233d665 564.BR fts_read ()
fea681da 565after the
3233d665 566.I FTSENT
fea681da 567structure has been returned by the function
3233d665 568.BR fts_read ()
fea681da 569in post-order.
3233d665 570.SS fts_children()
fea681da 571The
3233d665 572.BR fts_children ()
fea681da 573function returns a pointer to an
3233d665 574.I FTSENT
fea681da
MK
575structure describing the first entry in a NULL-terminated linked list of
576the files in the directory represented by the
3233d665 577.I FTSENT
fea681da 578structure most recently returned by
3233d665 579.BR fts_read ().
fea681da 580The list is linked through the
3233d665 581.I fts_link
fea681da 582field of the
3233d665 583.I FTSENT
fea681da
MK
584structure, and is ordered by the user-specified comparison function, if any.
585Repeated calls to
3233d665 586.BR fts_children ()
fea681da 587will recreate this linked list.
3233d665 588.sp
fea681da 589As a special case, if
3233d665 590.BR fts_read ()
fea681da 591has not yet been called for a hierarchy,
3233d665 592.BR fts_children ()
fea681da 593will return a pointer to the files in the logical directory specified to
3233d665 594.BR fts_open (),
75b94dc3 595that is, the arguments specified to
3233d665 596.BR fts_open ().
fea681da 597Otherwise, if the
3233d665 598.I FTSENT
fea681da 599structure most recently returned by
3233d665 600.BR fts_read ()
fea681da
MK
601is not a directory being visited in pre-order,
602or the directory does not contain any files,
3233d665 603.BR fts_children ()
fea681da 604returns
3233d665 605NULL
fea681da 606and sets
3233d665 607.I errno
fea681da
MK
608to zero.
609If an error occurs,
3233d665 610.BR fts_children ()
fea681da 611returns
3233d665 612NULL
fea681da 613and sets
3233d665 614.I errno
fea681da 615appropriately.
3233d665 616.sp
fea681da 617The
3233d665 618.I FTSENT
fea681da 619structures returned by
3233d665 620.BR fts_children ()
fea681da 621may be overwritten after a call to
3233d665
MK
622.BR fts_children (),
623.BR fts_close ()
fea681da 624or
3233d665 625.BR fts_read ()
fea681da 626on the same file hierarchy stream.
3233d665
MK
627.sp
628.I Option
fea681da 629may be set to the following value:
3233d665
MK
630.\" .Bl -tag -width FTS_NAMEONLY
631.TP 13
632.BR FTS_NAMEONLY
fea681da
MK
633Only the names of the files are needed.
634The contents of all the fields in the returned linked list of structures
635are undefined with the exception of the
3233d665 636.I fts_name
fea681da 637and
3233d665 638.I fts_namelen
fea681da 639fields.
3233d665
MK
640.\" .El
641..SS fts_set()
fea681da 642The function
3233d665 643.BR fts_set ()
fea681da
MK
644allows the user application to determine further processing for the
645file
3233d665 646.I f
fea681da 647of the stream
3233d665 648.IR ftsp .
fea681da 649The
3233d665 650.BR fts_set ()
fea681da
MK
651function
652returns 0 on success, and \-1 if an error occurs.
3233d665 653.I Option
fea681da 654must be set to one of the following values:
3233d665
MK
655.\" .Bl -tag -width FTS_PHYSICAL
656.TP 13
657.BR FTS_AGAIN
fea681da
MK
658Re-visit the file; any file type may be re-visited.
659The next call to
3233d665 660.BR fts_read ()
fea681da
MK
661will return the referenced file.
662The
3233d665 663.I fts_stat
fea681da 664and
3233d665 665.I fts_info
fea681da
MK
666fields of the structure will be reinitialized at that time,
667but no other fields will have been changed.
668This option is meaningful only for the most recently returned
669file from
3233d665 670.BR fts_read ().
fea681da
MK
671Normal use is for post-order directory visits, where it causes the
672directory to be re-visited (in both pre and post-order) as well as all
673of its descendants.
3233d665
MK
674.TP
675.BR FTS_FOLLOW
fea681da
MK
676The referenced file must be a symbolic link.
677If the referenced file is the one most recently returned by
3233d665 678.BR fts_read (),
fea681da 679the next call to
3233d665 680.BR fts_read ()
fea681da 681returns the file with the
3233d665 682.I fts_info
fea681da 683and
3233d665 684.I fts_statp
fea681da
MK
685fields reinitialized to reflect the target of the symbolic link instead
686of the symbolic link itself.
687If the file is one of those most recently returned by
3233d665 688.BR fts_children (),
fea681da 689the
3233d665 690.I fts_info
fea681da 691and
3233d665 692.I fts_statp
fea681da 693fields of the structure, when returned by
3233d665 694.BR fts_read (),
fea681da
MK
695will reflect the target of the symbolic link instead of the symbolic link
696itself.
697In either case, if the target of the symbolic link does not exist the
698fields of the returned structure will be unchanged and the
3233d665 699.I fts_info
fea681da 700field will be set to
3233d665
MK
701.BR FTS_SLNONE .
702.sp
fea681da
MK
703If the target of the link is a directory, the pre-order return, followed
704by the return of all of its descendants, followed by a post-order return,
705is done.
3233d665
MK
706.TP
707.BR FTS_SKIP
fea681da
MK
708No descendants of this file are visited.
709The file may be one of those most recently returned by either
3233d665 710.BR fts_children ()
fea681da 711or
3233d665
MK
712.BR fts_read ().
713.\" .El
714.SS fts_close()
fea681da 715The
3233d665 716.BR fts_close ()
fea681da 717function closes a file hierarchy stream
3233d665 718.I ftsp
fea681da 719and restores the current directory to the directory from which
3233d665 720.BR fts_open ()
fea681da 721was called to open
3233d665 722.IR ftsp .
fea681da 723The
3233d665 724.BR fts_close ()
fea681da
MK
725function
726returns 0 on success, and \-1 if an error occurs.
3233d665 727.SH ERRORS
fea681da 728The function
3233d665 729.BR fts_open ()
fea681da 730may fail and set
3233d665
MK
731.I errno
732for any of the errors specified for
733.BR open (2)
fea681da 734and
3233d665
MK
735.BR malloc (3).
736.sp
fea681da 737The function
3233d665 738.BR fts_close ()
fea681da 739may fail and set
3233d665
MK
740.I errno
741for any of the errors specified for
742.BR chdir (2)
fea681da 743and
3233d665
MK
744.BR close (2).
745.sp
fea681da 746The functions
3233d665 747.BR fts_read ()
fea681da 748and
3233d665 749.BR fts_children ()
fea681da 750may fail and set
3233d665
MK
751.I errno
752for any of the errors specified for
753.BR chdir (2),
754.BR malloc (3),
755.BR opendir (3),
756.BR readdir (3)
fea681da 757and
3233d665
MK
758.BR stat (2).
759.sp
fea681da 760In addition,
3233d665
MK
761.BR fts_children (),
762.BR fts_open ()
fea681da 763and
3233d665 764.BR fts_set ()
fea681da 765may fail and set
3233d665 766.I errno
fea681da 767as follows:
3233d665
MK
768.TP
769.B EINVAL
fea681da 770The options were invalid.
3233d665 771.SH VERSIONS
2b2581ee 772These functions are available in Linux since glibc2.
3233d665 773.SH "CONFORMING TO"
ca7b3c18 7744.4BSD.
deb5e281
MK
775.\" The following statement is years old, and seems no closer to
776.\" being true -- mtk
777.\" The
3233d665 778.\" .I fts
deb5e281 779.\" utility is expected to be included in a future
3233d665 780.\" POSIX.1
deb5e281 781.\" revision.
3233d665
MK
782.SH SEE ALSO
783.BR find (1),
784.BR chdir (2),
785.BR stat (2),
786.BR ftw (3),
787.BR qsort (3)