我从未见过检查文件是否正确关闭的真正用途。我的意思是,如果它没有关闭,那怎么办?你没有什么聪明的事可做。此外,我不确定是否存在现实世界的用例,其中 write
/reads
/flush
都不会失败,并且只有关闭
将会。
有人真正使用close
的返回值吗?
最佳答案
从收盘(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% 万无一失的代码,否则我很少打扰。
关于io - 是否有真正的程序检查文件关闭错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10943877/