Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show All 19 Lines | |||||
#include <typeinfo> | #include <typeinfo> | ||||
#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) | #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#endif | #endif | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
// for posix_fallocate | // for posix_fallocate, in config/CMakeLists.txt we check if it is present after | ||||
// this | |||||
#ifdef __linux__ | #ifdef __linux__ | ||||
#ifdef _POSIX_C_SOURCE | #ifdef _POSIX_C_SOURCE | ||||
#undef _POSIX_C_SOURCE | #undef _POSIX_C_SOURCE | ||||
#endif | #endif | ||||
#define _POSIX_C_SOURCE 200112L | #define _POSIX_C_SOURCE 200112L | ||||
▲ Show 20 Lines • Show All 1,177 Lines • ▼ Show 20 Lines | #elif defined(MAC_OSX) | ||||
// not the desired file size | // not the desired file size | ||||
fst.fst_length = length; | 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), static_cast<off_t>(offset) + length); | ftruncate(fileno(file), static_cast<off_t>(offset) + length); | ||||
#elif defined(__linux__) | #elif defined(HAVE_POSIX_FALLOCATE) | ||||
// 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)) { | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |