Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145817829
D21750.id62417.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D21750.id62417.diff
View Options
Index: lib/libc/gen/ftw.3
===================================================================
--- lib/libc/gen/ftw.3
+++ lib/libc/gen/ftw.3
@@ -20,7 +20,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 5, 2004
+.Dd September 21, 2019
.Dt FTW 3
.Os
.Sh NAME
@@ -157,6 +157,52 @@
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 -offset 2n
+#include <ftw.h>
+#include <stdio.h>
+
+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 <directory>\\n", argv[0]);
+ return (0);
+ } else
+ return (ftw(argv[1], ftw_callback, /*UNUSED*/ 10));
+}
+.Ed
.Sh ERRORS
The
.Fn ftw
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Feb 25, 9:22 PM (11 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28995622
Default Alt Text
D21750.id62417.diff (1 KB)
Attached To
Mode
D21750: ftw.3: Add examples
Attached
Detach File
Event Timeline
Log In to Comment