diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -184,6 +184,20 @@ } " HAVE_FUNC_ATTRIBUTE_DLLEXPORT) +check_cxx_source_compiles(" + // same as in src/util/system.cpp + #ifdef __linux__ + #ifdef _POSIX_C_SOURCE + #undef _POSIX_C_SOURCE + #endif + #define _POSIX_C_SOURCE 200112L + #endif // __linux__ + #include + int main() { + return posix_fallocate(0, 0, 0); + } +" HAVE_POSIX_FALLOCATE) + #__fdelt_chk's params and return type have changed from long unsigned int to # long int. See which one is present here. include(CheckPrototypeDefinition) diff --git a/src/config/bitcoin-config.h.cmake.in b/src/config/bitcoin-config.h.cmake.in --- a/src/config/bitcoin-config.h.cmake.in +++ b/src/config/bitcoin-config.h.cmake.in @@ -67,6 +67,7 @@ #cmakedefine HAVE_FUNC_ATTRIBUTE_VISIBILITY 1 #cmakedefine HAVE_FUNC_ATTRIBUTE_DLLEXPORT 1 +#cmakedefine HAVE_POSIX_FALLOCATE 1 #cmakedefine ENABLE_BIP70 1 #cmakedefine ENABLE_WALLET 1 diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -25,7 +25,8 @@ #endif #ifndef WIN32 -// for posix_fallocate +// for posix_fallocate, in config/CMakeLists.txt we check if it is present after +// this #ifdef __linux__ #ifdef _POSIX_C_SOURCE @@ -1219,7 +1220,7 @@ fcntl(fileno(file), F_PREALLOCATE, &fst); } ftruncate(fileno(file), static_cast(offset) + length); -#elif defined(__linux__) +#elif defined(HAVE_POSIX_FALLOCATE) // Version using posix_fallocate off_t nEndPos = (off_t)offset + length; posix_fallocate(fileno(file), 0, nEndPos);