Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 964 Lines • ▼ Show 20 Lines | try { | ||||
} | } | ||||
} | } | ||||
// create_directory didn't create the directory, it had to have existed | // create_directory didn't create the directory, it had to have existed | ||||
// already. | // already. | ||||
return false; | return false; | ||||
} | } | ||||
void FileCommit(FILE *file) { | bool FileCommit(FILE *file) { | ||||
// Harmless if redundantly called. | // harmless if redundantly called | ||||
fflush(file); | if (fflush(file) != 0) { | ||||
LogPrintf("%s: fflush failed: %d\n", __func__, errno); | |||||
return false; | |||||
} | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); | HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); | ||||
FlushFileBuffers(hFile); | if (FlushFileBuffers(hFile) == 0) { | ||||
LogPrintf("%s: FlushFileBuffers failed: %d\n", __func__, | |||||
GetLastError()); | |||||
return false; | |||||
} | |||||
#else | #else | ||||
#if defined(__linux__) || defined(__NetBSD__) | #if defined(__linux__) || defined(__NetBSD__) | ||||
fdatasync(fileno(file)); | // Ignore EINVAL for filesystems that don't support sync | ||||
if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { | |||||
LogPrintf("%s: fdatasync failed: %d\n", __func__, errno); | |||||
return false; | |||||
} | |||||
#elif defined(__APPLE__) && defined(F_FULLFSYNC) | #elif defined(__APPLE__) && defined(F_FULLFSYNC) | ||||
fcntl(fileno(file), F_FULLFSYNC, 0); | // Manpage says "value other than -1" is returned on success | ||||
if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { | |||||
LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno); | |||||
return false; | |||||
} | |||||
#else | #else | ||||
fsync(fileno(file)); | if (fsync(fileno(file)) != 0 && errno != EINVAL) { | ||||
LogPrintf("%s: fsync failed: %d\n", __func__, errno); | |||||
return false; | |||||
} | |||||
#endif | #endif | ||||
#endif | #endif | ||||
return true; | |||||
} | } | ||||
bool TruncateFile(FILE *file, unsigned int length) { | bool TruncateFile(FILE *file, unsigned int length) { | ||||
#if defined(WIN32) | #if defined(WIN32) | ||||
return _chsize(_fileno(file), length) == 0; | return _chsize(_fileno(file), length) == 0; | ||||
#else | #else | ||||
return ftruncate(fileno(file), length) == 0; | return ftruncate(fileno(file), length) == 0; | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |