2

我从未见过检查文件是否正确关闭的真正用途。我的意思是,如果它没有关闭,那会怎样?你没有什么聪明可做的。此外,我不确定是否有一个真实世界的用例,其中非write//会失败readsflush只有close意志会失败。

有没有人真正使用 的返回值close

4

1 回答 1

2

从关闭(2):

Not checking the return value of close() is a common but nevertheless serious
programming error. It is quite possible that errors on a previous write(2)
operation are first reported at the final close(). Not checking the return
value when closing the file may lead to silent loss of data. This can
especially be observed with NFS and with disk quota.

而且如果你在你的应用程序中使用信号close可能会被中断(EINTR)。

编辑:也就是说,除非我准备好处理这种情况并编写必须 100% 万无一失的代码,否则我很少打扰。

于 2012-06-08T06:58:14.627 回答