fclose 返回值检查 [英] fclose return value check

查看:24
本文介绍了fclose 返回值检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否需要检查fclose的返回值?如果我们成功打开了一个文件,它可能无法关闭的可能性有多大?

Is it required to check the return value of fclose? If we have successfully opened a file, what are the chances that it may fail to close?

谢谢!

问候,杰

推荐答案

当你 fwrite 到一个文件时,它实际上可能不会写任何东西,它可能会留在缓冲区中(在 FILE 对象内部).调用 fflush 实际上会将它写入磁盘.该操作可能会失败,例如,如果您刚用完磁盘空间,或者存在其他一些 I/O 错误.

When you fwrite to a file, it may not actually write anything, it may stay in a buffer (inside the FILE object). Calling fflush would actually write it to disk. That operation may fail, for example if you just ran out of disk space, or there is some other I/O error.

fclose 也会隐式刷新缓冲区,因此它可能会因相同的原因而失败.

fclose flushes the buffers implicitly too, so it may fail for the same reasons.

这篇关于fclose 返回值检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆