From 6fb7ee330af7acbbcd93d559761229329b4d0bf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 7 Nov 2025 12:47:20 +0100 Subject: [PATCH] build: simplify checks for fallocate() and posix_fallocate() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The bespoke test logic for those two functions was only necessary for old glibc versions which have long gone out of support. Align the checks with all other ones. Signed-off-by: Thomas Weißschuh --- configure.ac | 63 ++-------------------------------------------------- meson.build | 34 ++-------------------------- 2 files changed, 4 insertions(+), 93 deletions(-) diff --git a/configure.ac b/configure.ac index 6836f0564..297b9fb3f 100644 --- a/configure.ac +++ b/configure.ac @@ -614,6 +614,7 @@ AC_CHECK_FUNCS([ \ explicit_bzero \ __fpending \ __fpurge \ + fallocate \ fpurge \ fnmatch \ fsconfig \ @@ -652,6 +653,7 @@ AC_CHECK_FUNCS([ \ pidfd_open \ pidfd_send_signal \ posix_fadvise \ + posix_fallocate \ prctl \ qsort_r \ reallocarray \ @@ -1590,67 +1592,6 @@ UL_REQUIRES_LINUX([fallocate]) UL_REQUIRES_SYSCALL_CHECK([fallocate], [UL_CHECK_SYSCALL([fallocate])]) AM_CONDITIONAL([BUILD_FALLOCATE], [test "x$build_fallocate" = xyes]) -AS_IF([test "x$build_fallocate" = xyes], [ - dnl check for valid fallocate() function - dnl with 32 bits glibc 2.10, fallocate() exists but not fallocate64() - dnl when _FILE_OFFSET_BITS==64, fallocate() is redirect to fallocate64() - dnl and program can't be linked. - dnl AC_CHECK_FUNC can't catch such errors since it's redefining - dnl function prototype. - AC_MSG_CHECKING([for valid fallocate() function]) - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#ifdef HAVE_UNISTD_H -# include -#endif -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_LINUX_FALLOC_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -]],[[ - long ret; - ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0xfffffffful, 0xfffffffful); - if (ret != 0) { - return 1; - } - ]])],[ - AC_MSG_RESULT([yes]) - AC_DEFINE([HAVE_FALLOCATE], [1], [Have valid fallocate() function])],[ - AC_MSG_RESULT([no])]) -]) - -AS_IF([test "x$build_fallocate" = xyes], [ - dnl check for valid posix_fallocate() function - AC_MSG_CHECKING([for valid posix_fallocate() function]) - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#ifdef HAVE_UNISTD_H -# include -#endif -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_LINUX_FALLOC_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -]],[[ - long ret; - ret = posix_fallocate(0, 0xfffffffful, 0xfffffffful); - if (ret != 0) { - return 1; - } - ]])],[ - AC_MSG_RESULT([yes]) - AC_DEFINE([HAVE_POSIX_FALLOCATE], [1], [Have valid posix_fallocate() function])],[ - AC_MSG_RESULT([no])]) -]) - AC_ARG_ENABLE([unshare], AS_HELP_STRING([--disable-unshare], [do not build unshare]), diff --git a/meson.build b/meson.build index 7a995d612..00c24c751 100644 --- a/meson.build +++ b/meson.build @@ -606,6 +606,7 @@ funcs = ''' err errx explicit_bzero + fallocate fnmatch fseeko fsconfig @@ -644,6 +645,7 @@ funcs = ''' pidfd_open pidfd_send_signal posix_fadvise + posix_fallocate prctl qsort_r reallocarray @@ -890,38 +892,6 @@ summary('plymouth support', build_plymouth_support ? 'enabled' : 'disabled', section : 'components') -# check for valid fallocate() function -# with 32 bits glibc 2.10, fallocate() exists but not fallocate64() -# when _FILE_OFFSET_BITS==64, fallocate() is redirect to fallocate64() -# and program can't be linked. -code = ''' -#define _GNU_SOURCE -#include -#include - -int main(void) { - long ret; - ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0xfffffffful, 0xfffffffful); - return ret == 0 ? 0 : 1; -} -''' -have = cc.links(code, name : 'fallocate() function') -conf.set('HAVE_FALLOCATE', have ? 1 : false) - -code = ''' -#define _POSIX_C_SOURCE 200112L -#include -#include - -int main(void) { - long ret; - ret = posix_fallocate(0, 0xfffffffful, 0xfffffffful); - return ret == 0 ? 0 : 1; -} -''' -have = cc.links(code, name : 'posix_fallocate() function') -conf.set('HAVE_POSIX_FALLOCATE', have ? 1 : false) - use_hwclock_cmos = host_machine.cpu_family() in ['x86', 'x86_64'] message('Use CMOS clock: @0@'.format(use_hwclock_cmos)) conf.set('USE_HWCLOCK_CMOS', use_hwclock_cmos ? 1 : false) -- 2.47.3