state file atomicity

svn path=/trunk/boinc/; revision=9116
This commit is contained in:
David Anderson 2005-12-22 01:02:13 +00:00
parent ba23e3be09
commit 8b78163335
1 changed files with 3 additions and 1 deletions

View File

@ -132,11 +132,13 @@ int MFILE::close() {
int MFILE::flush() {
int n, old_len = len;
n = fwrite(buf, 1, len, f);
n = (int)fwrite(buf, 1, len, f);
len = 0;
if (n != old_len) return ERR_FWRITE;
if (fflush(f)) return ERR_FFLUSH;
#ifndef _WIN32
if (fsync(fileno(f)) < 0) return ERR_FSYNC;
#endif
return 0;
}