docs/173448: ftw.3 manual page example addition

Fernando fernando.apesteguia at gmail.com
Wed Nov 7 18:30:00 UTC 2012


>Number:         173448
>Category:       docs
>Synopsis:       ftw.3 manual page example addition
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 07 18:30:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Fernando
>Release:        9.0-RELEASE
>Organization:
>Environment:
FreeBSD beastie 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
While having a look at the ftw(3) man page, I noticed we lacked an example. The attached patch adds a small yet clear example on how to use this function.
>How-To-Repeat:
man ftw
>Fix:
Apply the attached patch if it is found to be suitable.

Patch attached with submission follows:

--- /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 <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


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-doc mailing list