Re: [PATCH] copy.c: use `sendfile()` for in-kernel file copying on Linux
From: George Hu <hidden>
Date: 2026-02-14 09:22:48
On 2/13/26 11:36 PM, Chris Torek wrote:
On Fri, Feb 13, 2026 at 4:47 AM George Hu [off-list ref] wrote:quoted
The `sendfile()` system call copies data between one file descriptor and another within the kernel, which is more efficient than the combination of `read()` and `write()`.sendfile() is found on other systems (notably BSDs), so perhaps ...quoted
Signed-off-by: George Hu <redacted> --- copy.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)diff --git a/copy.c b/copy.c index b668209b6c..d4b7cde764 100644 --- a/copy.c +++ b/copy.c@@ -7,8 +7,23 @@ #include "strbuf.h" #include "abspath.h" +#ifdef __linux__... this and the subsequent ifdef should be based on the feature, rather than the OS. Chris
Hello, Although the `sendfile()` system call exists in both Linux and BSDs, their semantics and APIs differ. The Linux prototype of `sendfile()` is: ssize_t sendfile(int out_fd, int in_fd, off_t *_Nullable offset, size_t count); While FreeBSD exposes: int sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr, off_t *sbytes, int flags); George