gpt4 book ai didi

c - "POSIX.1-2008 marks ftw() as obsolete"因此意味着什么?

转载 作者:太空狗 更新时间:2023-10-29 15:32:56 24 4
gpt4 key购买 nike

阅读 man 3 ftw 我观察到“POSIX.1-2008 将 ftw() 标记为已过时”。
现在我很担心并且想成为一个“好的程序员”并且可能尊重 ftw() 的过时性。我现在仍然在努力寻找我应该使用的其他什么是现在“最新的”,并且说到 ftw() 的替代品是什么让它过时了。

如果允许的话,我对两个子问题特别感兴趣。

  1. 我还能使用 ftw() 吗?
  2. 有没有办法估计这样做的风险
  3. 什么是ftw()的继承者

如果我愿意接受改进问题的建议,我希望得到怜悯,同时仍然很高兴得到帮助和接受,因为它具有挑战性,而且我已经很好地编写了这个问题。

最佳答案

是的,您应该避免使用过时的函数。对于 ftw(),替换为 nftw():

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

来自 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.

关于c - "POSIX.1-2008 marks ftw() as obsolete"因此意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19617783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com