2012-06-08 19 views
2

我從來沒有見過用於檢查文件是否正確關閉的實際用途。我的意思是,如果它沒有關閉,那麼是什麼?你沒有什麼明智的做法。除此之外,我不確定是否有真實世界用例,其中非write/reads/flush將會失敗,並且只有close會。任何真正的程序是否檢查文件關閉錯誤?

沒有人實際使用返回值close

+1

Windows內核不會期望文件系統在關閉操作時失敗。即文件系統驅動程序必須無條件地完成操作。雖然不知道其他操作系統。 –

回答

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%的傻瓜證明。

+0

不完全是我問的。真的有真正的程序能夠檢查嗎?手冊頁沒有說服我。如果你想確保數據到達磁盤,「flush」是你的朋友,而不是「close」,意外沖洗。 –

相關問題