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"
13134e9d19SSiva Chandra Reddy 
14134e9d19SSiva Chandra Reddy #include <errno.h>
15*09f2f81cSSiva Chandra Reddy #include <sys/syscall.h> // For syscall numbers.
165793c849SAlex Brachet 
175793c849SAlex Brachet namespace __llvm_libc {
185793c849SAlex Brachet 
19a0b65a7bSMichael Jones LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) {
205793c849SAlex Brachet   long ret = __llvm_libc::syscall(SYS_write, fd, buf, count);
215793c849SAlex Brachet   if (ret < 0) {
22134e9d19SSiva Chandra Reddy     errno = -ret;
235793c849SAlex Brachet     return -1;
245793c849SAlex Brachet   }
255793c849SAlex Brachet   return ret;
265793c849SAlex Brachet }
275793c849SAlex Brachet 
285793c849SAlex Brachet } // namespace __llvm_libc
29