Reputation: 2482
What would happen if I were to use write() to write some data to a file on disk. But my application were to crash before flushing. Is it guaranteed that my data will get eventually flushed to disk if there is no system failure?
Upvotes: 6
Views: 1550
Reputation: 154017
If you're using write
(and not fwrite
or std::ostream::write
),
then there is no in process buffering. If there is no system failure,
then the data will, sooner or later (and generally fairly soon) be
written to disk.
If you're really concerned by data integrity, you can or in the flags
O_DSYNC
and O_SYNC
to the flags when you open the file. If you do
this, you are guaranteed that the data is physically written to the disk
before the return from write
.
Upvotes: 5