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. πŸ“š


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. πŸ’…βœ¨