--- /usr/src/lib/libc/gen/ftw.3 2012-01-03 04:26:08.000000000 +0100 +++ ftw_man/ftw.3 2012-11-07 19:18:48.000000000 +0100 @@ -155,6 +155,54 @@ will stop processing the tree and return the value from .Fa fn . Both functions return \-1 if an error is detected. +.Sh EXAMPLES +Following there is a small example that shows how +.Nm +works. It traverses the file tree starting at the directory pointed +by the only program argument and shows the complete path and a brief +indicator about the file type. +.Bd -literal +#include +#include + +int +ftw_callback(const char *path, const struct stat *sb, int typeflag) +{ + char type; + + switch(typeflag) { + case FTW_F: + type = 'F'; + break; + case FTW_D: + type = 'D'; + break; + case FTW_DNR: + type = '-'; + break; + case FTW_NS: + type = 'X'; + break; + } + + printf("[%c] %s\n", type, path); + + return (0); +} + +int +main(int argc, char **argv) +{ + + if (argc != 2) { + printf("Usage %s \n", argv[0]); + return (0); + } else { + return (ftw(argv[1], ftw_callback, /*UNUSED*/ 10)); + } + +} +.Ed .Sh ERRORS The .Fn ftw