From owner-svn-src-stable@freebsd.org Thu Mar 19 10:31:48 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id F411225B413; Thu, 19 Mar 2020 10:31:47 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48jjrM5lZpz4R9j; Thu, 19 Mar 2020 10:31:47 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5F0B998DA; Thu, 19 Mar 2020 10:31:47 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02JAVlSk001331; Thu, 19 Mar 2020 10:31:47 GMT (envelope-from 0mp@FreeBSD.org) Received: (from 0mp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02JAVlIp001330; Thu, 19 Mar 2020 10:31:47 GMT (envelope-from 0mp@FreeBSD.org) Message-Id: <202003191031.02JAVlIp001330@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: 0mp set sender to 0mp@FreeBSD.org using -f From: Mateusz Piotrowski <0mp@FreeBSD.org> Date: Thu, 19 Mar 2020 10:31:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r359127 - stable/12/lib/libc/gen X-SVN-Group: stable-12 X-SVN-Commit-Author: 0mp X-SVN-Commit-Paths: stable/12/lib/libc/gen X-SVN-Commit-Revision: 359127 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 10:31:48 -0000 Author: 0mp (doc,ports committer) Date: Thu Mar 19 10:31:46 2020 New Revision: 359127 URL: https://svnweb.freebsd.org/changeset/base/359127 Log: MFC 358674, 358916: Add examples to ftw.3 ftw.3: Add examples PR: 173448 [1] Submitted by: fernape@ (previous version) [1] Reviewed by: jilles Approved by: bcr (mentor) Differential Revision: https://reviews.freebsd.org/D21750 ftw.3: Follow style(9) in the example Reported by: oshogbo Approved by: bcr (mentor) Differential Revision: https://reviews.freebsd.org/D24043 Modified: stable/12/lib/libc/gen/ftw.3 Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libc/gen/ftw.3 ============================================================================== --- stable/12/lib/libc/gen/ftw.3 Thu Mar 19 10:20:32 2020 (r359126) +++ stable/12/lib/libc/gen/ftw.3 Thu Mar 19 10:31:46 2020 (r359127) @@ -20,7 +20,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 5, 2004 +.Dd March 12, 2020 .Dt FTW 3 .Os .Sh NAME @@ -157,6 +157,66 @@ and 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 an example that shows how +.Nm nftw +can be used. +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 +#include +#include + +int +nftw_callback(const char *path, const struct stat *sb, int typeflag, struct FTW *ftw) +{ + char type; + + switch(typeflag) { + case FTW_F: + type = 'F'; + break; + case FTW_D: + type = 'D'; + break; + case FTW_DNR: + type = '-'; + break; + case FTW_DP: + type = 'd'; + break; + case FTW_NS: + type = 'X'; + break; + case FTW_SL: + type = 'S'; + break; + case FTW_SLN: + type = 's'; + break; + default: + type = '?'; + 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 (EX_USAGE); + } else + return (nftw(argv[1], nftw_callback, /* UNUSED */ 1, 0)); +} +.Ed .Sh ERRORS The .Fn ftw