Function replacement of nftw

161 Views Asked by At

ALL,

According to this, ntfw is obsolete in POSIX.1-2008.

Is there a replacement of this function? Or I should use something else across the board?

TIA!

1

There are 1 best solutions below

0
On

From the link you cited:

POSIX.1-2001, SVr4, SUSv1. POSIX.1-2008 marks ftw() as obsolete. ...

On some systems ftw() will never use FTW_SL, on other systems FTW_SL occurs only for symbolic links that do not point to an existing file, and again on other systems ftw() will use FTW_SL for each symbolic link. For predictable control, use nftw().

My interpretation is that ftw was obsoleted in favor of nftw. So use that.

Personally, I would just implement my own. Every intro level CS textbook I've ever read covers filesystem traversal. I would use a fifo queue of dir handles and iterative breadth-first loop to avoid unnecessary function call overhead, both in the traversal and in the per-file hook (implemented as a function pointer in ftw).