brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · ec89232 Raw
42 lines · cpp
1//===-- Linux implementation of sendfile ----------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/sys/sendfile/sendfile.h"10 11#include "src/__support/OSUtil/syscall.h" // For internal syscall function.12#include "src/__support/common.h"13 14#include "src/__support/libc_errno.h"15#include "src/__support/macros/config.h"16#include <sys/sendfile.h>17#include <sys/syscall.h> // For syscall numbers.18 19namespace LIBC_NAMESPACE_DECL {20 21LLVM_LIBC_FUNCTION(ssize_t, sendfile,22                   (int out_fd, int in_fd, off_t *offset, size_t count)) {23#ifdef SYS_sendfile24  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendfile, in_fd,25                                                      out_fd, offset, count);26#elif defined(SYS_sendfile64)27  // Same as sendfile but can handle large offsets28  static_assert(sizeof(off_t) == 8);29  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendfile64, in_fd,30                                                      out_fd, offset, count);31#else32#error "sendfile and sendfile64 syscalls not available."33#endif34  if (ret < 0) {35    libc_errno = static_cast<int>(-ret);36    return -1;37  }38  return ret;39}40 41} // namespace LIBC_NAMESPACE_DECL42