【问题标题】:Is any real program checks for file close errors?是否有任何真正的程序检查文件关闭错误?
【发布时间】:2012-06-12 05:16:21
【问题描述】:

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

真的有人使用close的返回值吗?

【问题讨论】:

  • Windows 内核从不期望文件系统在关闭操作时失败。 IE。文件系统驱动程序必须无条件地完成操作。不过不知道其他操作系统。

标签: io filesystems operating-system


【解决方案1】:

从关闭(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% 万无一失的代码,否则我很少打扰。

【讨论】:

  • 不完全是我问的。是否有真正的程序可以实际检查它?手册页没有说服我。如果您想确保数据进入磁盘,flush 是您的朋友,而不是 close,它会意外刷新。
猜你喜欢
  • 2013-02-21
  • 1970-01-01
  • 2012-01-23
  • 2021-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多