1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Use copy_file_range to copy files

The copy_file_range syscall (introduced in Linux kernel
version 4.5) can copy files more efficiently via server-side
copy etc.
* admin/merge-gnulib (GNULIB_MODULES): Add copy-file-range.
* lib/copy-file-range.c, m4/copy-file-range.m4:
New files, copied from Gnulib.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* src/fileio.c (Fcopy_file): Try copy_file_range first,
falling back on read+write only if copy_file_range failed or
if the input is empty and so could be a /proc file.
This commit is contained in:
Paul Eggert 2019-06-06 21:18:11 -07:00
parent 111408a0e9
commit 486a81f387
6 changed files with 123 additions and 9 deletions

36
m4/copy-file-range.m4 Normal file
View file

@ -0,0 +1,36 @@
# copy-file-range.m4
dnl Copyright 2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_COPY_FILE_RANGE],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
dnl Persuade glibc <unistd.h> to declare copy_file_range.
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
dnl Use AC_LINK_IFELSE, rather than AC_CHECK_FUNCS or a variant,
dnl since we don't want AC_CHECK_FUNCS's checks for glibc stubs.
dnl Programs that use copy_file_range must fall back on read+write
dnl anyway, and there's little point to substituting the Gnulib stub
dnl for a glibc stub.
AC_CACHE_CHECK([for copy_file_range], [gl_cv_func_copy_file_range],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <unistd.h>
]],
[[ssize_t (*func) (int, off_t *, int, off_t, size_t, unsigned)
= copy_file_range;
return func (0, 0, 0, 0, 0, 0) & 127;
]])
],
[gl_cv_func_copy_file_range=yes],
[gl_cv_func_copy_file_range=no])
])
if test "$gl_cv_func_copy_file_range" != yes; then
HAVE_COPY_FILE_RANGE=0
fi
])