1
by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages. |
1 |
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved |
2
by Francesco Paolo Lovergine
* Alligned to linux main manpages edition. |
2 |
.TH "FTW" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" |
1
by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages. |
3 |
.\" ftw |
4 |
.SH NAME |
|
5 |
ftw \- traverse (walk) a file tree
|
|
6 |
.SH SYNOPSIS |
|
7 |
.LP
|
|
8 |
\fB#include <ftw.h>
|
|
9 |
.br
|
|
10 |
.sp
|
|
11 |
int ftw(const char *\fP\fIpath\fP\fB, int (*\fP\fIfn\fP\fB)(const |
|
12 |
char *, |
|
13 |
.br
|
|
14 |
\ \ \ \ \ \ const struct stat *\fP\fIptr\fP\fB, int\fP \fIflag\fP\fB), |
|
15 |
int\fP
|
|
16 |
\fIndirs\fP\fB); \fP |
|
17 |
\fB
|
|
18 |
.br
|
|
19 |
\fP
|
|
20 |
.SH DESCRIPTION |
|
21 |
.LP
|
|
22 |
The \fIftw\fP() function shall recursively descend the directory hierarchy |
|
23 |
rooted in \fIpath\fP. For each object in the |
|
24 |
hierarchy, \fIftw\fP() shall call the function pointed to by \fIfn\fP, |
|
25 |
passing it a pointer to a null-terminated character string |
|
26 |
containing the name of the object, a pointer to a \fBstat\fP structure |
|
27 |
containing information about the object, and an integer. |
|
28 |
Possible values of the integer, defined in the \fI<ftw.h>\fP header, |
|
29 |
are: |
|
30 |
.TP 7 |
|
31 |
FTW_D |
|
32 |
For a directory. |
|
33 |
.TP 7 |
|
34 |
FTW_DNR |
|
35 |
For a directory that cannot be read. |
|
36 |
.TP 7 |
|
37 |
FTW_F |
|
38 |
For a file. |
|
39 |
.TP 7 |
|
40 |
FTW_SL |
|
41 |
For a symbolic link (but see also FTW_NS below). |
|
42 |
.TP 7 |
|
43 |
FTW_NS |
|
44 |
For an object other than a symbolic link on which \fIstat\fP() could |
|
45 |
not successfully be |
|
46 |
executed. If the object is a symbolic link and \fIstat\fP() failed, |
|
47 |
it is unspecified whether |
|
48 |
\fIftw\fP() passes FTW_SL or FTW_NS to the user-supplied function. |
|
49 |
.sp
|
|
50 |
.LP
|
|
51 |
If the integer is FTW_DNR, descendants of that directory shall not |
|
52 |
be processed. If the integer is FTW_NS, the \fBstat\fP |
|
53 |
structure contains undefined values. An example of an object that |
|
54 |
would cause FTW_NS to be passed to the function pointed to by |
|
55 |
\fIfn\fP would be a file in a directory with read but without execute |
|
56 |
(search) permission. |
|
57 |
.LP
|
|
58 |
The \fIftw\fP() function shall visit a directory before visiting any |
|
59 |
of its descendants. |
|
60 |
.LP
|
|
61 |
The \fIftw\fP() function shall use at most one file descriptor for |
|
62 |
each level in the tree. |
|
63 |
.LP
|
|
64 |
The argument \fIndirs\fP should be in the range [1, {OPEN_MAX}]. |
|
65 |
.LP
|
|
66 |
The tree traversal shall continue until either the tree is exhausted, |
|
67 |
an invocation of \fIfn\fP returns a non-zero value, or |
|
68 |
some error, other than [EACCES], is detected within \fIftw\fP(). |
|
69 |
.LP
|
|
70 |
The \fIndirs\fP argument shall specify the maximum number of directory |
|
71 |
streams or file descriptors or both available for use by |
|
72 |
\fIftw\fP() while traversing the tree. When \fIftw\fP() returns it |
|
73 |
shall close any directory streams and file descriptors it uses |
|
74 |
not counting any opened by the application-supplied \fIfn\fP function. |
|
75 |
.LP
|
|
76 |
The results are unspecified if the application-supplied \fIfn\fP function |
|
77 |
does not preserve the current working directory. |
|
78 |
.LP
|
|
79 |
The \fIftw\fP() function need not be reentrant. A function that is |
|
80 |
not required to be reentrant is not required to be |
|
81 |
thread-safe. |
|
82 |
.SH RETURN VALUE |
|
83 |
.LP
|
|
84 |
If the tree is exhausted, \fIftw\fP() shall return 0. If the function |
|
85 |
pointed to by \fIfn\fP returns a non-zero value, |
|
86 |
\fIftw\fP() shall stop its tree traversal and return whatever value |
|
87 |
was returned by the function pointed to by \fIfn\fP. If |
|
88 |
\fIftw\fP() detects an error, it shall return -1 and set \fIerrno\fP |
|
89 |
to indicate the error. |
|
90 |
.LP
|
|
91 |
If \fIftw\fP() encounters an error other than [EACCES] (see FTW_DNR |
|
92 |
and FTW_NS above), it shall return -1 and set \fIerrno\fP |
|
93 |
to indicate the error. The external variable \fIerrno\fP may contain |
|
94 |
any error value that is possible when a directory is opened |
|
95 |
or when one of the \fIstat\fP functions is executed on a directory |
|
96 |
or file. |
|
97 |
.SH ERRORS |
|
98 |
.LP
|
|
99 |
The \fIftw\fP() function shall fail if: |
|
100 |
.TP 7 |
|
101 |
.B EACCES |
|
102 |
Search permission is denied for any component of \fIpath\fP or read |
|
103 |
permission is denied for \fIpath\fP. |
|
104 |
.TP 7 |
|
105 |
.B ELOOP |
|
106 |
A loop exists in symbolic links encountered during resolution of the |
|
107 |
\fIpath\fP argument. |
|
108 |
.TP 7 |
|
109 |
.B ENAMETOOLONG |
|
110 |
The length of the \fIpath\fP argument exceeds {PATH_MAX} or a pathname |
|
111 |
component is longer than {NAME_MAX}. |
|
112 |
.TP 7 |
|
113 |
.B ENOENT |
|
114 |
A component of \fIpath\fP does not name an existing file or \fIpath\fP |
|
115 |
is an empty string. |
|
116 |
.TP 7 |
|
117 |
.B ENOTDIR |
|
118 |
A component of \fIpath\fP is not a directory. |
|
119 |
.TP 7 |
|
120 |
.B EOVERFLOW |
|
121 |
A field in the \fBstat\fP structure cannot be represented correctly |
|
122 |
in the current programming environment for one or more |
|
123 |
files found in the file hierarchy. |
|
124 |
.sp
|
|
125 |
.LP
|
|
126 |
The \fIftw\fP() function may fail if: |
|
127 |
.TP 7 |
|
128 |
.B EINVAL |
|
129 |
The value of the \fIndirs\fP argument is invalid. |
|
130 |
.TP 7 |
|
131 |
.B ELOOP |
|
132 |
More than {SYMLOOP_MAX} symbolic links were encountered during resolution |
|
133 |
of the \fIpath\fP argument. |
|
134 |
.TP 7 |
|
135 |
.B ENAMETOOLONG |
|
136 |
Pathname resolution of a symbolic link produced an intermediate result |
|
137 |
whose length exceeds {PATH_MAX}. |
|
138 |
.sp
|
|
139 |
.LP
|
|
140 |
In addition, if the function pointed to by \fIfn\fP encounters system |
|
141 |
errors, \fIerrno\fP may be set accordingly. |
|
142 |
.LP
|
|
143 |
\fIThe following sections are informative.\fP |
|
144 |
.SH EXAMPLES |
|
145 |
.SS Walking a Directory Structure |
|
146 |
.LP
|
|
147 |
The following example walks the current directory structure, calling |
|
148 |
the \fIfn\fP function for every directory entry, using at |
|
149 |
most 10 file descriptors: |
|
150 |
.sp
|
|
151 |
.RS
|
|
152 |
.nf
|
|
153 |
||
154 |
\fB#include <ftw.h>
|
|
155 |
\&...
|
|
156 |
if (ftw(".", fn, 10) != 0) { |
|
157 |
perror("ftw"); exit(2); |
|
158 |
} |
|
159 |
\fP
|
|
160 |
.fi
|
|
161 |
.RE
|
|
162 |
.SH APPLICATION USAGE |
|
163 |
.LP
|
|
164 |
The \fIftw\fP() function may allocate dynamic storage during its operation. |
|
165 |
If \fIftw\fP() is forcibly terminated, such as by |
|
166 |
\fIlongjmp\fP() or \fIsiglongjmp\fP() being |
|
167 |
executed by the function pointed to by \fIfn\fP or an interrupt routine, |
|
168 |
\fIftw\fP() does not have a chance to free that storage, |
|
169 |
so it remains permanently allocated. A safe way to handle interrupts |
|
170 |
is to store the fact that an interrupt has occurred, and |
|
171 |
arrange to have the function pointed to by \fIfn\fP return a non-zero |
|
172 |
value at its next invocation. |
|
173 |
.SH RATIONALE |
|
174 |
.LP
|
|
175 |
None. |
|
176 |
.SH FUTURE DIRECTIONS |
|
177 |
.LP
|
|
178 |
None. |
|
179 |
.SH SEE ALSO |
|
180 |
.LP
|
|
181 |
\fIlongjmp\fP() , \fIlstat\fP() , \fImalloc\fP() , \fInftw\fP() , |
|
182 |
\fIopendir\fP() , \fIsiglongjmp\fP() , \fIstat\fP() , the Base Definitions |
|
183 |
volume of |
|
184 |
IEEE\ Std\ 1003.1-2001, \fI<ftw.h>\fP, \fI<sys/stat.h>\fP |
|
185 |
.SH COPYRIGHT |
|
186 |
Portions of this text are reprinted and reproduced in electronic form |
|
187 |
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology |
|
188 |
-- Portable Operating System Interface (POSIX), The Open Group Base |
|
189 |
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of |
|
190 |
Electrical and Electronics Engineers, Inc and The Open Group. In the |
|
191 |
event of any discrepancy between this version and the original IEEE and |
|
192 |
The Open Group Standard, the original IEEE and The Open Group Standard |
|
193 |
is the referee document. The original Standard can be obtained online at |
|
194 |
http://www.opengroup.org/unix/online.html . |