Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 1,182 Lines • ▼ Show 20 Lines | |||||
#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] = {}; | ||||
fseek(file, offset, SEEK_SET); | if (fseek(file, offset, SEEK_SET)) { | ||||
return; | |||||
} | |||||
while (length > 0) { | while (length > 0) { | ||||
unsigned int now = 65536; | unsigned int now = 65536; | ||||
if (length < now) { | if (length < now) { | ||||
now = length; | now = length; | ||||
} | } | ||||
// Allowed to fail; this function is advisory anyway. | // Allowed to fail; this function is advisory anyway. | ||||
fwrite(buf, 1, now, file); | fwrite(buf, 1, now, file); | ||||
length -= now; | length -= now; | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |