diff options
author | Ralph Boehme <slow@samba.org> | 2021-06-24 14:13:50 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2021-06-30 16:51:29 +0000 |
commit | 4dcc04228df233be15efe9c31bcbaba822b140c4 (patch) | |
tree | 0d17b381a2aa33956722c477c016c74b1f1b4b4d /lib/replace | |
parent | 7d101c82dfd1a961255fc449d3ec3611b2c21276 (diff) | |
download | samba-4dcc04228df233be15efe9c31bcbaba822b140c4.tar.gz |
replace: copy_file_range()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12033
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/replace')
-rw-r--r-- | lib/replace/replace.c | 25 | ||||
-rw-r--r-- | lib/replace/replace.h | 10 | ||||
-rw-r--r-- | lib/replace/wscript | 12 |
3 files changed, 46 insertions, 1 deletions
diff --git a/lib/replace/replace.c b/lib/replace/replace.c index 99b18e82590..0652cb4e6d6 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -1056,3 +1056,28 @@ const char *rep_getprogname(void) #endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */ } #endif /* HAVE_GETPROGNAME */ + +#ifndef HAVE_COPY_FILE_RANGE +# ifdef HAVE_SYSCALL_COPY_FILE_RANGE +# include <sys/syscall.h> +# endif +ssize_t rep_copy_file_range(int fd_in, + loff_t *off_in, + int fd_out, + loff_t *off_out, + size_t len, + unsigned int flags) +{ +# ifdef HAVE_SYSCALL_COPY_FILE_RANGE + return syscall(__NR_copy_file_range, + fd_in, + off_in, + fd_out, + off_out, + len, + flags); +# endif /* HAVE_SYSCALL_COPY_FILE_RANGE */ + errno = ENOSYS; + return -1; +} +#endif /* HAVE_COPY_FILE_RANGE */ diff --git a/lib/replace/replace.h b/lib/replace/replace.h index e08bf7c2e58..a546185d47a 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -964,6 +964,16 @@ int rep_memset_s(void *dest, size_t destsz, int ch, size_t count); const char *rep_getprogname(void); #endif +#ifndef HAVE_COPY_FILE_RANGE +#define copy_file_range rep_copy_file_range +ssize_t rep_copy_file_range(int fd_in, + loff_t *off_in, + int fd_out, + loff_t *off_out, + size_t len, + unsigned int flags); +#endif /* HAVE_COPY_FILE_RANGE */ + #ifndef FALL_THROUGH # ifdef HAVE_FALLTHROUGH_ATTRIBUTE # define FALL_THROUGH __attribute__ ((fallthrough)) diff --git a/lib/replace/wscript b/lib/replace/wscript index 5d6324ef619..12f995f3198 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -454,6 +454,16 @@ def configure(conf): conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create') conf.CHECK_FUNCS('port_create') conf.CHECK_FUNCS('getprogname') + if not conf.CHECK_FUNCS('copy_file_range'): + conf.CHECK_CODE(''' +#include <sys/syscall.h> +#include <unistd.h> +syscall(SYS_copy_file_range,0,NULL,0,NULL,0,0); + ''', + 'HAVE_SYSCALL_COPY_FILE_RANGE', + msg='Checking whether we have copy_file_range system call') + if conf.CONFIG_SET('HAVE_COPY_FILE_RANGE') or conf.CONFIG_SET('HAVE_SYSCALL_COPY_FILE_RANGE'): + conf.DEFINE('USE_COPY_FILE_RANGE', 1) conf.SET_TARGET_TYPE('attr', 'EMPTY') @@ -835,7 +845,7 @@ REPLACEMENT_FUNCTIONS = { 'strsep', 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv', 'utime', 'utimes', 'dup2', 'chown', 'link', 'readlink', 'symlink', 'lchown', 'realpath', 'memmem', 'vdprintf', - 'dprintf', 'get_current_dir_name', + 'dprintf', 'get_current_dir_name', 'copy_file_range', 'strerror_r', 'clock_gettime', 'memset_s'], 'timegm.c': ['timegm'], # Note: C99_VSNPRINTF is not a function, but a special condition |