Skip to content

Commit 63d5ed2

Browse files
committed
Merge #18437: util: Detect posix_fallocate() instead of assuming
182dbdf 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 182dbdf Tree-SHA512: f9ed4bd661f33ff6b2b1150591e860b3c1f44e12b87c35e870d06a7013c4e841ed2bf17b41ad6b18fe471b0b23a4b5e42cf1400637180888e0bc56c254fe0766
2 parents 36c0abd + 182dbdf commit 63d5ed2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

configure.ac

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,22 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
846846
[ AC_MSG_RESULT(no)]
847847
)
848848

849+
dnl Check for posix_fallocate
850+
AC_MSG_CHECKING(for posix_fallocate)
851+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
852+
// same as in src/util/system.cpp
853+
#ifdef __linux__
854+
#ifdef _POSIX_C_SOURCE
855+
#undef _POSIX_C_SOURCE
856+
#endif
857+
#define _POSIX_C_SOURCE 200112L
858+
#endif // __linux__
859+
#include <fcntl.h>]],
860+
[[ int f = posix_fallocate(0, 0, 0); ]])],
861+
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_POSIX_FALLOCATE, 1,[Define this symbol if you have posix_fallocate]) ],
862+
[ AC_MSG_RESULT(no)]
863+
)
864+
849865
AC_MSG_CHECKING([for visibility attribute])
850866
AC_LINK_IFELSE([AC_LANG_SOURCE([
851867
int foo_def( void ) __attribute__((visibility("default")));

src/util/system.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
#ifndef WIN32
20-
// for posix_fallocate
20+
// for posix_fallocate, in configure.ac we check if it is present after this
2121
#ifdef __linux__
2222

2323
#ifdef _POSIX_C_SOURCE
@@ -1019,7 +1019,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
10191019
}
10201020
ftruncate(fileno(file), static_cast<off_t>(offset) + length);
10211021
#else
1022-
#if defined(__linux__)
1022+
#if defined(HAVE_POSIX_FALLOCATE)
10231023
// Version using posix_fallocate
10241024
off_t nEndPos = (off_t)offset + length;
10251025
if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;

0 commit comments

Comments
 (0)