xref: /llvm-project/libc/src/unistd/linux/write.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
15793c849SAlex Brachet //===-- Linux implementation of write -------------------------------------===//
25793c849SAlex Brachet //
35793c849SAlex Brachet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45793c849SAlex Brachet // See https://llvm.org/LICENSE.txt for license information.
55793c849SAlex Brachet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65793c849SAlex Brachet //
75793c849SAlex Brachet //===----------------------------------------------------------------------===//
85793c849SAlex Brachet 
95793c849SAlex Brachet #include "src/unistd/write.h"
105793c849SAlex Brachet 
113cc2161cSSiva Chandra Reddy #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
125793c849SAlex Brachet #include "src/__support/common.h"
13*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
14204587a3SSiva Chandra Reddy #include "src/errno/libc_errno.h"
15134e9d19SSiva Chandra Reddy 
1609f2f81cSSiva Chandra Reddy #include <sys/syscall.h> // For syscall numbers.
175793c849SAlex Brachet 
18*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
195793c849SAlex Brachet 
20a0b65a7bSMichael Jones LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) {
21b6bc9d72SGuillaume Chatelet   ssize_t ret =
22b6bc9d72SGuillaume Chatelet       LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_write, fd, buf, count);
235793c849SAlex Brachet   if (ret < 0) {
24f0a3954eSMichael Jones     libc_errno = static_cast<int>(-ret);
255793c849SAlex Brachet     return -1;
265793c849SAlex Brachet   }
275793c849SAlex Brachet   return ret;
285793c849SAlex Brachet }
295793c849SAlex Brachet 
30*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
31