3 dnl Copyright 2019-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_COPY_FILE_RANGE],
10 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11 AC_REQUIRE([AC_CANONICAL_HOST])
13 dnl Persuade glibc <unistd.h> to declare copy_file_range.
14 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16 dnl Use AC_LINK_IFELSE, rather than AC_CHECK_FUNCS or a variant,
17 dnl since we don't want AC_CHECK_FUNCS's checks for glibc stubs.
18 dnl Programs that use copy_file_range must fall back on read+write
19 dnl anyway, and there's little point to substituting the Gnulib stub
23 AC_CACHE_CHECK([for copy_file_range], [gl_cv_func_copy_file_range],
28 [[ssize_t (*func) (int, off_t *, int, off_t *, size_t, unsigned)
30 return func (0, 0, 0, 0, 0, 0) & 127;
33 [gl_cv_func_copy_file_range=yes],
34 [gl_cv_func_copy_file_range=no])
36 gl_cv_onwards_func_copy_file_range="$gl_cv_func_copy_file_range"
39 gl_CHECK_FUNCS_ANDROID([copy_file_range], [[#include <unistd.h>]])
40 gl_cv_func_copy_file_range="$ac_cv_func_copy_file_range"
43 if test "$gl_cv_func_copy_file_range" != yes; then
44 HAVE_COPY_FILE_RANGE=0
45 case "$gl_cv_onwards_func_copy_file_range" in
46 future*) REPLACE_COPY_FILE_RANGE=1 ;;
49 AC_DEFINE([HAVE_COPY_FILE_RANGE], 1,
50 [Define to 1 if the function copy_file_range exists.])
54 # See copy-file-range.c comment re pre-5.3 Linux kernel bugs.
55 # We should be able to remove this hack in 2025.
56 REPLACE_COPY_FILE_RANGE=1;;