|
|
1.1 root 1: .TH FTW 3
2: .CT 2 dirs
3: .SH NAME
4: ftw \- file tree walk
5: .SH SYNOPSIS
6: .nf
7: .B #include <ftw.h>
8: .PP
9: .B int ftw(path, fn, depth)
10: .B char *path;
11: .B int (*fn)();
12: .B int depth;
13: .PP
14: .B #include <sys/types.h>
15: .B #include <sys/stat.h>
16: .PP
17: .IB fn "(name, statb, code, S)"
18: .B char *name;
19: .B struct stat *statb;
20: .B struct FTW *S;
21: .fi
22: .SH DESCRIPTION
23: .I Ftw
24: recursively descends the directory hierarchy
25: rooted in
26: .IR path .
27: For each entry in the hierarchy,
28: .I ftw
29: calls
30: .IR fn ,
31: passing it information about the entry:
32: a pointer to a null-terminated pathname
33: string, a pointer to a
34: .B stat
35: structure (see
36: .IR stat (2)),
37: and a pointer to the following structure.
38: .PP
39: .EX
40: .ta \w'struct 'u +\w'int level 'u
41: struct FTW {
42: int quit; \fRsee below\fP
43: int base; &name[base] \fRpoints to basename\fP
44: int level; \fRrecursion level (initially 0)\fP
45: };
46: .EE
47: .LP
48: Possible values of
49: .IR code ,
50: defined in
51: .FR <ftw.h> ,
52: are
53: .TF FTW_DNR
54: .PD 0
55: .TP
56: .B FTW_D
57: Entry is a directory (before visiting descendants).
58: .TP
59: .B FTW_DP
60: Entry is a directory (after visiting descendants).
61: .TP
62: .B FTW_SL
63: Entry is a symbolic link.
64: .TP
65: .B FTW_F
66: Entry is some other kind of file.
67: .TP
68: .B FTW_DNR
69: Entry is a directory that cannot be read;
70: no descendants will be visited.
71: .TP
72: .B FTW_NS
73: .I Lstat
74: (see
75: .IR stat (2))
76: failed on
77: .IR name ;
78: contents of
79: .I statb
80: are undefined
81: .TP
82: .B FTW_NSL
83: .I Lstat
84: succeeded, but
85: .I stat
86: failed; contents of
87: .I statb
88: are undefined.
89: .PD
90: .PP
91: The tree traversal continues until the tree is exhausted or
92: .I fn
93: returns a nonzero value.
94: When the tree is exhausted,
95: .I ftw
96: returns zero.
97: When
98: .I fn
99: returns a nonzero value,
100: .I ftw
101: stops and returns that value.
102: .PP
103: Normally symbolic links are not followed.
104: But if on a symbolic link
105: .RB ( FTW_SL )
106: .IR fn
107: sets
108: .B S->quit
109: to
110: .BR FTW_FOLLOW ,
111: .IR ftw
112: will next attempt to follow the link.
113: .PP
114: .I Ftw
115: normally visits a readable directory twice, before and
116: after visiting its descendants.
117: But if on a previsit
118: .RB ( FTW_D )
119: .I fn
120: sets
121: .B S->quit
122: to
123: .B FTW_SKD,
124: .I ftw
125: will skip the descendants and the postvisit
126: .RB ( FTW_DP ).
127: .PP
128: .I Ftw
129: uses one file descriptor for each level in the tree up to a
130: maximum of
131: .I depth
132: (or 1, if
133: .IR depth <1)
134: descriptors.
135: .I Depth
136: must not exceed the number of available file descriptors; small
137: values of
138: .I depth
139: may cause
140: .I ftw
141: to run slowly, but will not change its effect.
142: .SH "SEE ALSO"
143: .IR stat (2),
144: .IR directory (3)
145: .SH DIAGNOSTICS
146: .I Ftw
147: returns \-1
148: with
149: .I errno
150: set to
151: .B ENOMEM
152: when
153: .IR malloc (3)
154: fails.
155: .PP
156: .I Errno
157: is set appropriately when
158: .I ftw
159: calls
160: .I fn
161: with code
162: .BR FTW_DNR ,
163: .BR FTW_NS ,
164: or
165: .BR FTW_NSL .
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.