1 .\" $NetBSD: ftw.3,v 1.5 2010/04/30 04:39:16 jruoho Exp $
3 .\" From OpenBSD: ftw.3,v 1.4 2003/10/30 18:52:58 jmc Exp
5 .\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
7 .\" Permission to use, copy, modify, and distribute this software for any
8 .\" purpose with or without fee is hereby granted, provided that the above
9 .\" copyright notice and this permission notice appear in all copies.
11 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 .\" Sponsored in part by the Defense Advanced Research Projects
20 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
21 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
28 .Nd traverse (walk) a file tree
33 .Fa "const char *path"
34 .Fa "int (*fn)(const char *, const struct stat *, int)"
39 .Fa "const char *path"
40 .Fa "int (*fn)(const\ char\ *, const\ struct\ stat\ *, int, struct\ FTW\ *)"
46 These functions are provided for compatibility with legacy code.
47 New code should use the
56 functions traverse (walk) the directory hierarchy rooted in
58 For each object in the hierarchy, these functions call the function
63 function passes this function a pointer to a NUL-terminated string containing
64 the name of the object, a pointer to a stat structure corresponding to the
65 object, and an integer flag.
68 function passes the aforementioned arguments plus a pointer to a
70 structure as defined by
75 int base; /* offset of basename into pathname */
76 int level; /* directory depth relative to starting point */
80 Possible values for the flag passed to
83 .Bl -tag -width FTW_DNR
87 A directory being visited in pre-order.
89 A directory which cannot be read.
90 The directory will not be descended into.
92 A directory being visited in post-order
97 information was available.
98 The contents of the stat structure are undefined.
102 A symbolic link with a non-existent target
103 .Pq Fn nftw No only .
108 function traverses the tree in pre-order.
109 That is, it processes the directory before the directory's contents.
113 argument specifies the maximum number of file descriptors
114 to keep open while traversing the tree.
115 It has no effect in this implementation.
119 function has an additional
121 argument with the following possible values:
122 .Bl -tag -width FTW_MOUNT
124 Physical walk, don't follow symbolic links.
126 The walk will not cross a mount point.
128 Process directories in post-order.
129 Contents of a directory are visited before the directory itself.
132 traverses the tree in pre-order.
134 Change to a directory before reading it.
137 will change its starting directory.
138 The current working directory will be restored to its original value before
143 If the tree was traversed successfully, the
148 If the function pointed to by
150 returns a non-zero value,
154 will stop processing the tree and return the value from
156 Both functions return \-1 if an error is detected.
162 functions may fail and set
164 for any of the errors specified for the library functions
176 function may fail and set
178 for any of the errors specified for
180 In addition, either function may fail and set
187 argument is less than 1 or greater than
208 revision marked the function
214 argument is currently ignored.