io - 是否有真正的程序检查文件关闭错误?

标签 io filesystems operating-system

我从未见过检查文件是否正确关闭的真正用途。我的意思是,如果它没有关闭,那怎么办?你没有什么聪明的事可做。此外,我不确定是否存在现实世界的用例,其中 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/

相关文章:

java - 在 Java 中仅从 JSONArray 获取值,即不获取键

c - 原始终端模式 - 如何接受输入?

linux - 安装实例存储损坏 ec2 实例

file-io - 操作系统如何计算文件大小?

Powershell system.io.compression 压缩文件和/或文件夹

c# - 在C#程序中访问linux文件系统

linux - 格式化为FAT32后,Pen Drive无法在音频播放器中播放音频

windows - 我一次可以打开多少个 TCP 套接字?

c++ - 如何让两个子进程互相等待

java - 扫描仪在使用 next() 或 nextFoo() 后跳过 nextLine()?