| 1021 | } |
| 1022 | |
| 1023 | bool FileCommit(FILE *file) |
| 1024 | { |
| 1025 | if (fflush(file) != 0) { // harmless if redundantly called |
| 1026 | LogPrintf("%s: fflush failed: %d\n", __func__, errno); |
| 1027 | return false; |
| 1028 | } |
| 1029 | #ifdef WIN32 |
| 1030 | HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); |
| 1031 | if (FlushFileBuffers(hFile) == 0) { |
| 1032 | LogPrintf("%s: FlushFileBuffers failed: %d\n", __func__, GetLastError()); |
| 1033 | return false; |
| 1034 | } |
| 1035 | #else |
| 1036 | #if defined(__linux__) || defined(__NetBSD__) |
| 1037 | if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync |
| 1038 | LogPrintf("%s: fdatasync failed: %d\n", __func__, errno); |
| 1039 | return false; |
| 1040 | } |
| 1041 | #elif defined(MAC_OSX) && defined(F_FULLFSYNC) |
| 1042 | if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success |
| 1043 | LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno); |
| 1044 | return false; |
| 1045 | } |
| 1046 | #else |
| 1047 | if (fsync(fileno(file)) != 0 && errno != EINVAL) { |
| 1048 | LogPrintf("%s: fsync failed: %d\n", __func__, errno); |
| 1049 | return false; |
| 1050 | } |
| 1051 | #endif |
| 1052 | #endif |
| 1053 | return true; |
| 1054 | } |
| 1055 | |
| 1056 | bool TruncateFile(FILE *file, unsigned int length) { |
| 1057 | #if defined(WIN32) |
no outgoing calls
no test coverage detected