|
Lines 155-160
Link Here
|
| 155 |
will stop processing the tree and return the value from |
155 |
will stop processing the tree and return the value from |
| 156 |
.Fa fn . |
156 |
.Fa fn . |
| 157 |
Both functions return \-1 if an error is detected. |
157 |
Both functions return \-1 if an error is detected. |
|
|
158 |
.Sh EXAMPLES |
| 159 |
Following there is a small example that shows how |
| 160 |
.Nm |
| 161 |
works. It traverses the file tree starting at the directory pointed |
| 162 |
by the only program argument and shows the complete path and a brief |
| 163 |
indicator about the file type. |
| 164 |
.Bd -literal |
| 165 |
#include <ftw.h> |
| 166 |
#include <stdio.h> |
| 167 |
|
| 168 |
int |
| 169 |
ftw_callback(const char *path, const struct stat *sb, int typeflag) |
| 170 |
{ |
| 171 |
char type; |
| 172 |
|
| 173 |
switch(typeflag) { |
| 174 |
case FTW_F: |
| 175 |
type = 'F'; |
| 176 |
break; |
| 177 |
case FTW_D: |
| 178 |
type = 'D'; |
| 179 |
break; |
| 180 |
case FTW_DNR: |
| 181 |
type = '-'; |
| 182 |
break; |
| 183 |
case FTW_NS: |
| 184 |
type = 'X'; |
| 185 |
break; |
| 186 |
} |
| 187 |
|
| 188 |
printf("[%c] %s\n", type, path); |
| 189 |
|
| 190 |
return (0); |
| 191 |
} |
| 192 |
|
| 193 |
int |
| 194 |
main(int argc, char **argv) |
| 195 |
{ |
| 196 |
|
| 197 |
if (argc != 2) { |
| 198 |
printf("Usage %s <directory>\n", argv[0]); |
| 199 |
return (0); |
| 200 |
} else { |
| 201 |
return (ftw(argv[1], ftw_callback, /*UNUSED*/ 10)); |
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
.Ed |
| 158 |
.Sh ERRORS |
206 |
.Sh ERRORS |
| 159 |
The |
207 |
The |
| 160 |
.Fn ftw |
208 |
.Fn ftw |