ftw(3) Library Functions Manual ftw(3) ftw, nftw - (libc -lc) #include int nftw(const char *dirpath, typeof(int (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)) *fn, int nopenfd, int flags); [[deprecated]] int ftw(const char *dirpath, typeof(int (const char *fpath, const struct stat *sb, int typeflag)) *fn, int nopenfd); glibc ( feature_test_macros(7)): nftw(): _XOPEN_SOURCE >= 500 nftw() dirpath fn() . ( ). nopenfd nftw() . nftw() . nftw() . nftw() fn() : fpath sb typeflag ftwbuf. fpath nftw() dirpath dirpath . sb stat stat(2) fpath. typeflag fn() : FTW_F fpath . FTW_D fpath . FTW_DNR fpath . FTW_DP fpath FTW_DEPTH flags. ( FTW_DEPTH flags typeflag FTW_D.) fpath. FTW_NS stat(2) fpath . fpath stat(2). sb . FTW_SL fpath FTW_PHYS flags. FTW_SLN fpath . ( FTW_PHYS.) sb fn() lstat(2) "". ( BUGS.) (ftwbuf) nftw() fn() FTW: struct FTW { int base; int level; }; base ( ) fpath. level fpath (dirpath 0). fn() nftw(). fn() 0 nftw() ( malloc(3)) -1. nftw() fn(). fn(). longjmp(3) . flags nftw() OR : FTW_ACTIONRETVAL ( glibc 2.3.3) glibc nftw() fn() . fn() : FTW_CONTINUE nftw() . FTW_SKIP_SIBLINGS fn() . FTW_SKIP_SUBTREE fn() (typeflag FTW_D) fn(). nftw() . FTW_STOP nftw() FTW_STOP. fn() . _GNU_SOURCE ( ) FTW_ACTIONRETVAL . FTW_CHDIR chdir(2) . fpath. ( fpath fn.) FTW_DEPTH fn() . ( .) FTW_MOUNT ( ). FTW_PHYS . ( .) . FTW_PHYS FTW_DEPTH fn() . ftw() ftw() nftw(). : o ftw() flags. nftw() flags . o fn() . o typeflag fn() : FTW_F FTW_D FTW_DNR FTW_NS () FTW_SL. 0 -1 . fn() fn() ftw() nftw(). nftw() FTW_ACTIONRETVAL fn() FTW_STOP nftw(). attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |nftw() | | MT-Safe cwd | +------------+------------------------------------+--------------------+ |ftw() | | MT-Safe | +------------+------------------------------------+--------------------+ ( glibc) ftw() FTW_SL FTW_SL ftw() FTW_SL . fpath stat(2) POSIX.1-2008 FTW_NS FTW_SL typeflag. nftw(). POSIX.1-2008. ftw() POSIX.1-2001, SVr4, SUSv1. POSIX.1-2008 . nftw() glibc 2.1. POSIX.1-2001, SUSv1. FTW_SL POSIX.1-2001, SUSv1. POSIX.1-2008 fn . POSIX.1-2008 typeflag fn() FTW_SLN sb ( lstat(2) ). glibc POSIX . glibc 2.4 sb FTW_SLN typeflag. ( .) glibc 2.30 glibc ( ) POSIX. . . flags nftw(). #define _XOPEN_SOURCE 500 #include #include #include #include #include static int display_info(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { printf("%-3s %2d ", (tflag == FTW_D) ? "d" : (tflag == FTW_DNR) ? "dnr" : (tflag == FTW_DP) ? "dp" : (tflag == FTW_F) ? "f" : (tflag == FTW_NS) ? "ns" : (tflag == FTW_SL) ? "sl" : (tflag == FTW_SLN) ? "sln" : "???", ftwbuf->level); if (tflag == FTW_NS) printf("-------"); else printf("%7jd", (intmax_t) sb->st_size); printf(" %-40s %d %s\n", fpath, ftwbuf->base, fpath + ftwbuf->base); return 0; /* nftw() */ } int main(int argc, char *argv[]) { int flags = 0; if (argc > 2 && strchr(argv[2], 'd') != NULL) flags |= FTW_DEPTH; if (argc > 2 && strchr(argv[2], 'p') != NULL) flags |= FTW_PHYS; if (nftw((argc < 2) ? "." : argv[1], display_info, 20, flags) == -1) { perror("nftw"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } stat(2), fts(3), readdir(3) 3 . . : . 6.18 8 2026 ftw(3)