ftw.h(7POSIX)
π ftw.h β file tree traversal π
okay bestie, listen up, this is ftw.h from the POSIX Programmer's Manual, and it's section 7POSIX if you're keeping track. it's giving "header file that knows where all your files live." let's get into it π¦
β¨ PROLOG β¨
so like, real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (bestie, go check the corresponding Linux manual page for the actual Linux behavior, no cap), or honestly the interface may not even be implemented on Linux at all. vibe check your platform first, fr fr. π
πΈ NAME πΈ
ftw.h β file tree traversal. that's it, that's the whole thing. it's the header that lets you walk a whole directory tree like it's nothing. main character energy. π
π SYNOPSIS π
#include <ftw.h>
literally just that one line, iconic.
π DESCRIPTION π
okay so here's where it gets juicy. the <ftw.h> header shall define the FTW structure, and that structure shall include at least these members:
int base
int level
that's the bare minimum, btw β "at least," so a platform could add more. don't be surprised if there's extra. π
π the FTW_* constants for the third argument π
the <ftw.h> header shall define these symbolic constants, and they get used as the values of the third argument to the application-supplied function β you know, the one you pass as the second argument to ftw() and nftw(). yes bestie, it's callback city. π«Ά
FTW_Fβ non-directory file. just a regular file doing its thing.FTW_Dβ directory. it's a folder, bestie. πFTW_DNRβ directory without read permission. she's locked, you're not getting in. πFTW_DPβ directory with subdirectories visited. all the babies have been handled. βFTW_NSβ unknown type;stat()failed. oop. πFTW_SLβ symbolic link. the little shortcut queen. πFTW_SLNβ symbolic link that names a nonexistent file. she points at nothing. ghost behavior. π»
β the FTW_* constants for the fourth argument β
and these ones, the <ftw.h> header shall define for use as the values of the fourth argument to nftw():
FTW_PHYSβ physical walk, does not follow symbolic links. otherwise,nftw()follows links but does not walk down any path that crosses itself. so either way, no infinite loop nonsense. periodt.FTW_MOUNTβ the walk does not cross a mount point. stays in its own lane, respectfully.FTW_DEPTHβ all subdirectories are visited before the directory itself. bottom-up, like a true reverse-order girlie.FTW_CHDIRβ the walk changes to each directory before reading it. she moves in, then reads the room. π
π§ the functions π§
the following shall be declared as functions, and they may also be defined as macros. function prototypes shall be provided. so like, these are real ones:
int ftw(const char *, int (*)(const char *, const struct stat *,
int), int);
int nftw(const char *, int (*)(const char *, const struct stat *,
int, struct FTW *), int, int);
copy those exactly, bestie, don't freestyle the signatures. π₯
π the stat structure situation π
the <ftw.h> header shall define the stat structure and the symbolic names for st_mode and the file type test macros as described in <sys/stat.h>. so like, all that good stuff comes along for the ride.
and heads up: inclusion of the <ftw.h> header may also make visible all symbols from <sys/stat.h>. so don't be shocked when extra names show up β that's just how she is. πΈ
the following sections are informative. (translation: they're the chill, non-normative bonus content. still gotta include them tho. β¨)
π APPLICATION USAGE π
None.
like. literally none. the section is empty. she said "no thoughts, head empty." π
π RATIONALE π
None.
again, nothing. the rationale girlies are resting today. π΄
π¦ FUTURE DIRECTIONS π¦
None.
no future plans, she's living in the present moment. manifesting nothing. β¨
π SEE ALSO π
<sys_stat.h>- The System Interfaces volume of POSIX.1β2017,
ftw(),nftw()
go read those if you want the full lore, iykyk. π
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! π«Ά this one's brought to you by IEEE/The Open Group, 2017 β yeah, 2017, she's vintage but she still ate. now go traverse some file trees and slay. π β¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms