Question

Reading man 3 ftw I observe that "POSIX.1-2008 marks ftw() as obsolete".
Now I am concerned and want to be a "nice programmer" and maybe respect obsoleteness of ftw(). Still I struggle now with finding out what else I should use that is now "up-to-date" and in a matter of speaking what the replacement for ftw() is that made it obsolete.

If allowed I am especially interested in two sub questions.

  1. Can I still use ftw()?
  2. Is there a way to estimate the risks involved doing so?
  3. What is the successor of ftw()

I hope for mercy if and am open for suggestion to improve the question, while still being happy to be helped and accepted given it is challenging and I tried well to compose the question.

Was it helpful?

Solution

Yes, you should avoid using obsolete functions. For ftw(), the replacement is nftw():

int nftw(const char *path, int (*fn)(const char *,
       const struct stat *, int, struct FTW *), int fd_limit, int flags);

From Open Group:

The ftw() function may allocate dynamic storage during its operation. If ftw() is forcibly terminated, such as by longjmp() or siglongjmp() being executed by the function pointed to by fn or an interrupt routine, ftw() does not have a chance to free that storage, so it remains permanently allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and arrange to have the function pointed to by fn return a non-zero value at its next invocation.

Applications should use the nftw() function instead of the obsolescent ftw() function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top