Reputation:
fclose()
flushes buffered output data.
Does close()
also flush buffered output data?
Upvotes: 0
Views: 1208
Reputation: 120011
There are no buffers in a C program associated with an open file descriptor, and so no buffered data to speak about.
Your OS may or may not have some buffers associated with an open file descriptor (or with a device on which the corresponding file resides), depending on the nature of the file. These are normally invisible at the application program level, and not affected by close
.
Upvotes: 5
Reputation: 2813
Form this source:
A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. It is not common for a file system to flush the buffers when the stream is closed. If you need to be sure that the data is physically stored use fsync(2). (It will depend on the disk hardware at this point.)
Upvotes: 4