brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · b04783e Raw
44 lines · cpp
1//===-- Linux implementation of sendmsg -----------------------------------===//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/socket/sendmsg.h"10 11#include <linux/net.h>   // For SYS_SOCKET socketcall number.12#include <sys/syscall.h> // For syscall numbers.13 14#include "hdr/types/ssize_t.h"15#include "hdr/types/struct_msghdr.h"16#include "src/__support/OSUtil/syscall.h" // For internal syscall function.17#include "src/__support/common.h"18#include "src/__support/libc_errno.h"19 20namespace LIBC_NAMESPACE_DECL {21 22LLVM_LIBC_FUNCTION(ssize_t, sendmsg,23                   (int sockfd, const struct msghdr *msg, int flags)) {24#ifdef SYS_sendmsg25  ssize_t ret =26      LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_sendmsg, sockfd, msg, flags);27#elif defined(SYS_socketcall)28  unsigned long sockcall_args[3] = {static_cast<unsigned long>(sockfd),29                                    reinterpret_cast<unsigned long>(msg),30                                    static_cast<unsigned long>(flags)};31  ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(32      SYS_socketcall, SYS_SENDMSG, sockcall_args);33#else34#error "socket and socketcall syscalls unavailable for this platform."35#endif36  if (ret < 0) {37    libc_errno = static_cast<int>(-ret);38    return -1;39  }40  return ret;41}42 43} // namespace LIBC_NAMESPACE_DECL44