immutable: Add tests.
[gnulib.git] / m4 / copy-file-range.m4
blob82904e9fce43589c245751073c3d803cacf80559
1 # copy-file-range.m4
2 dnl Copyright 2019-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_COPY_FILE_RANGE],
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11   dnl Persuade glibc <unistd.h> to declare copy_file_range.
12   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14   dnl Use AC_LINK_IFELSE, rather than AC_CHECK_FUNCS or a variant,
15   dnl since we don't want AC_CHECK_FUNCS's checks for glibc stubs.
16   dnl Programs that use copy_file_range must fall back on read+write
17   dnl anyway, and there's little point to substituting the Gnulib stub
18   dnl for a glibc stub.
19   AC_CACHE_CHECK([for copy_file_range], [gl_cv_func_copy_file_range],
20     [AC_LINK_IFELSE(
21        [AC_LANG_PROGRAM(
22           [[#include <unistd.h>
23           ]],
24           [[ssize_t (*func) (int, off_t *, int, off_t, size_t, unsigned)
25               = copy_file_range;
26             return func (0, 0, 0, 0, 0, 0) & 127;
27           ]])
28        ],
29        [gl_cv_func_copy_file_range=yes],
30        [gl_cv_func_copy_file_range=no])
31     ])
33   if test "$gl_cv_func_copy_file_range" != yes; then
34     HAVE_COPY_FILE_RANGE=0
35   fi