On Tue, 9 Nov 2010 18:57:03 +0000 Nick Treleaven nick.treleaven@btinternet.com wrote:
On Tue, 9 Nov 2010 20:28:43 +0200 Dimitar Zhekov dimitar.zhekov@gmail.com wrote:
With binary I/O we have fsync(), which really flushes the data. Even fflush() and fclose() are not guaranteed to do that.
Strange, why is that?
fsync() is in section 2 system calls; you can't have such a function in section 3. Closing a file (be it close or fclose) does not flush - maybe for for performance reasons, dunno.
Well, g_file_set_contents() uses buffered I/O, so obviously it's acceptable too.
Yes, it uses fwrite and then errno.
Probably fwrite(), fflush() and then errno? fflush() is guaranteed to set errno AFAIK.
But since we don't write the file line-by-line or something, _why_ do we use buffered I/O in the first place?..
I don't know. But changing implementation often introduces bugs, so I'm reluctant to do so (besides fixing fclose failure).
Well the current implementation is not exactly bug-free. :)