Handle the result of posix_fallocate system call

Github-Pull: #15650
Rebased-From: 5d35ae3326
This commit is contained in:
Luca Venturini
2019-03-23 04:20:40 +00:00
committed by fanquake
parent f792b25d14
commit c52dd120fd

View File

@@ -1085,11 +1085,12 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
fcntl(fileno(file), F_PREALLOCATE, &fst);
}
ftruncate(fileno(file), fst.fst_length);
#elif defined(__linux__)
#else
#if defined(__linux__)
// Version using posix_fallocate
off_t nEndPos = (off_t)offset + length;
posix_fallocate(fileno(file), 0, nEndPos);
#else
if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;
#endif
// Fallback version
// TODO: just write one byte per block
static const char buf[65536] = {};