当前位置: 动力学知识库 > 问答 > 编程问答 >

c - What would "POSIX.1-2008 marks ftw() as obsolete" consequently mean?

问题描述:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: