1 //===-- Linux implementation of sendfile ----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/sys/sendfile/sendfile.h"
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
14 #include "src/errno/libc_errno.h"
15 #include <sys/sendfile.h>
16 #include <sys/syscall.h> // For syscall numbers.
18 namespace LIBC_NAMESPACE
{
20 LLVM_LIBC_FUNCTION(ssize_t
, sendfile
,
21 (int out_fd
, int in_fd
, off_t
*offset
, size_t count
)) {
23 ssize_t ret
= LIBC_NAMESPACE::syscall_impl
<ssize_t
>(SYS_sendfile
, in_fd
,
24 out_fd
, offset
, count
);
25 #elif defined(SYS_sendfile64)
26 // Same as sendfile but can handle large offsets
27 static_assert(sizeof(off_t
) == 8);
28 ssize_t ret
= LIBC_NAMESPACE::syscall_impl
<ssize_t
>(SYS_sendfile64
, in_fd
,
29 out_fd
, offset
, count
);
31 #error "sendfile and sendfile64 syscalls not available."
34 libc_errno
= static_cast<int>(-ret
);
40 } // namespace LIBC_NAMESPACE