doc: Add documentation about math_errhandling.
[gnulib.git] / m4 / copy-file-range.m4
blob4ef75f62d40ae5e3111d01ac968f3cf24f567632
1 # copy-file-range.m4
2 # serial 5
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
20   dnl for a glibc stub.
21   case "$host_os" in
22     *-gnu* | gnu*)
23       AC_CACHE_CHECK([for copy_file_range], [gl_cv_func_copy_file_range],
24         [AC_LINK_IFELSE(
25            [AC_LANG_PROGRAM(
26               [[#include <unistd.h>
27               ]],
28               [[ssize_t (*func) (int, off_t *, int, off_t *, size_t, unsigned)
29                   = copy_file_range;
30                 return func (0, 0, 0, 0, 0, 0) & 127;
31               ]])
32            ],
33            [gl_cv_func_copy_file_range=yes],
34            [gl_cv_func_copy_file_range=no])
35         ])
36       gl_cv_onwards_func_copy_file_range="$gl_cv_func_copy_file_range"
37       ;;
38     *)
39       gl_CHECK_FUNCS_ANDROID([copy_file_range], [[#include <unistd.h>]])
40       gl_cv_func_copy_file_range="$ac_cv_func_copy_file_range"
41       ;;
42   esac
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 ;;
47     esac
48   else
49     AC_DEFINE([HAVE_COPY_FILE_RANGE], 1,
50       [Define to 1 if the function copy_file_range exists.])
52     case $host_os in
53       linux*)
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;;
57     esac
58   fi