diff options
-rw-r--r-- | lib/replace/wscript | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/replace/wscript b/lib/replace/wscript index 3cc0adeeb34..9c23d549dab 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -456,10 +456,32 @@ def configure(conf): conf.CHECK_FUNCS('getprogname') if not conf.CHECK_FUNCS('copy_file_range'): conf.CHECK_CODE(''' -syscall(SYS_copy_file_range,0,NULL,0,NULL,0,0); + int src_fd = -1, dst_fd = -1, ret; + ssize_t written; + char src[]="/tmp/test.XXXXXX"; + char dst[]="/tmp/test.XXXXXX"; + src_fd = mkstemp(src); + if (src_fd == -1) {ret = 1; goto cleanup;} + dst_fd = mkstemp(dst); + if (dst_fd == -1) {ret = 2; goto cleanup;} + written = pwrite(src_fd, "x", 1, 0); + if (written != 1) {ret = 3; goto cleanup;} + written = syscall(SYS_copy_file_range,src_fd,0,dst_fd,0,1,0); + if (written != 1) { + printf("SYS_copy_file_range failed: %s", strerror(errno)); + ret = 4; goto cleanup; + } + ret = 0; + cleanup: + if (src_fd != -1) close(src_fd); + if (dst_fd != -1) close(dst_fd); + unlink(src); + unlink(dst); + return ret; ''', 'HAVE_SYSCALL_COPY_FILE_RANGE', - headers='sys/syscall.h unistd.h', + headers='errno.h string.h stdio.h sys/syscall.h unistd.h sys/types.h sys/stat.h fcntl.h', + execute=True, 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) |