mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge #18437: util: Detect posix_fallocate() instead of assuming
182dbdf0f4b6e6484b0d4588aaefacc75862a99c util: Detect posix_fallocate() instead of assuming (Vasil Dimov) Pull request description: Don't assume that `posix_fallocate()` is available on Linux and not available on other operating systems. At least FreeBSD has it and we are not using it. Properly check whether `posix_fallocate()` is present and use it if it is. ACKs for top commit: laanwj: ACK 182dbdf0f4b6e6484b0d4588aaefacc75862a99c Tree-SHA512: f9ed4bd661f33ff6b2b1150591e860b3c1f44e12b87c35e870d06a7013c4e841ed2bf17b41ad6b18fe471b0b23a4b5e42cf1400637180888e0bc56c254fe0766
This commit is contained in:
parent
5ef0a3c1a7
commit
c49e573e47
16
configure.ac
16
configure.ac
@ -990,6 +990,22 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
|
|||||||
[ AC_MSG_RESULT(no)]
|
[ AC_MSG_RESULT(no)]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
dnl Check for posix_fallocate
|
||||||
|
AC_MSG_CHECKING(for posix_fallocate)
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||||
|
// 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 <fcntl.h>]],
|
||||||
|
[[ int f = posix_fallocate(0, 0, 0); ]])],
|
||||||
|
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_POSIX_FALLOCATE, 1,[Define this symbol if you have posix_fallocate]) ],
|
||||||
|
[ AC_MSG_RESULT(no)]
|
||||||
|
)
|
||||||
|
|
||||||
AC_MSG_CHECKING([for visibility attribute])
|
AC_MSG_CHECKING([for visibility attribute])
|
||||||
AC_LINK_IFELSE([AC_LANG_SOURCE([
|
AC_LINK_IFELSE([AC_LANG_SOURCE([
|
||||||
int foo_def( void ) __attribute__((visibility("default")));
|
int foo_def( void ) __attribute__((visibility("default")));
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// for posix_fallocate
|
// for posix_fallocate, in configure.ac we check if it is present after this
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
#ifdef _POSIX_C_SOURCE
|
#ifdef _POSIX_C_SOURCE
|
||||||
@ -1170,7 +1170,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
|
|||||||
}
|
}
|
||||||
ftruncate(fileno(file), static_cast<off_t>(offset) + length);
|
ftruncate(fileno(file), static_cast<off_t>(offset) + length);
|
||||||
#else
|
#else
|
||||||
#if defined(__linux__)
|
#if 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;
|
||||||
if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;
|
if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user