Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 1,112 Lines • ▼ Show 20 Lines | #if defined(WIN32) | ||||
HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); | HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); | ||||
LARGE_INTEGER nFileSize; | LARGE_INTEGER nFileSize; | ||||
int64_t nEndPos = (int64_t)offset + length; | int64_t nEndPos = (int64_t)offset + length; | ||||
nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF; | nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF; | ||||
nFileSize.u.HighPart = nEndPos >> 32; | nFileSize.u.HighPart = nEndPos >> 32; | ||||
SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN); | SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN); | ||||
SetEndOfFile(hFile); | SetEndOfFile(hFile); | ||||
#elif defined(MAC_OSX) | #elif defined(MAC_OSX) | ||||
// OSX specific version. | // OSX specific version | ||||
// NOTE: Contrary to other OS versions, the OSX version assumes that | |||||
// NOTE: offset is the size of the file. | |||||
fstore_t fst; | fstore_t fst; | ||||
fst.fst_flags = F_ALLOCATECONTIG; | fst.fst_flags = F_ALLOCATECONTIG; | ||||
fst.fst_posmode = F_PEOFPOSMODE; | fst.fst_posmode = F_PEOFPOSMODE; | ||||
fst.fst_offset = 0; | fst.fst_offset = 0; | ||||
fst.fst_length = (off_t)offset + length; | // mac os fst_length takes the number of free bytes to allocate, | ||||
// not the desired file size | |||||
fst.fst_length = length; | |||||
fst.fst_bytesalloc = 0; | fst.fst_bytesalloc = 0; | ||||
if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) { | if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) { | ||||
fst.fst_flags = F_ALLOCATEALL; | fst.fst_flags = F_ALLOCATEALL; | ||||
fcntl(fileno(file), F_PREALLOCATE, &fst); | fcntl(fileno(file), F_PREALLOCATE, &fst); | ||||
} | } | ||||
ftruncate(fileno(file), fst.fst_length); | ftruncate(fileno(file), static_cast<off_t>(offset) + length); | ||||
#elif defined(__linux__) | #elif defined(__linux__) | ||||
// Version using posix_fallocate. | // Version using posix_fallocate | ||||
off_t nEndPos = (off_t)offset + length; | off_t nEndPos = (off_t)offset + length; | ||||
posix_fallocate(fileno(file), 0, nEndPos); | posix_fallocate(fileno(file), 0, nEndPos); | ||||
#else | #else | ||||
// Fallback version | // Fallback version | ||||
// TODO: just write one byte per block | // TODO: just write one byte per block | ||||
static const char buf[65536] = {}; | static const char buf[65536] = {}; | ||||
if (fseek(file, offset, SEEK_SET)) { | if (fseek(file, offset, SEEK_SET)) { | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |