160c0d303SJoseph Huber //===-- Implementation of fwrite_unlocked ---------------------------------===// 260c0d303SJoseph Huber // 360c0d303SJoseph Huber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 460c0d303SJoseph Huber // See https://llvm.org/LICENSE.txt for license information. 560c0d303SJoseph Huber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 660c0d303SJoseph Huber // 760c0d303SJoseph Huber //===----------------------------------------------------------------------===// 860c0d303SJoseph Huber 960c0d303SJoseph Huber #include "src/stdio/fwrite_unlocked.h" 1060c0d303SJoseph Huber #include "src/__support/File/file.h" 1160c0d303SJoseph Huber 125aed6d67SMichael Jones #include "hdr/types/FILE.h" 13*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 1460c0d303SJoseph Huber #include "src/errno/libc_errno.h" 155aed6d67SMichael Jones #include <stddef.h> 1660c0d303SJoseph Huber 17*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 1860c0d303SJoseph Huber 1960c0d303SJoseph Huber LLVM_LIBC_FUNCTION(size_t, fwrite_unlocked, 2060c0d303SJoseph Huber (const void *__restrict buffer, size_t size, size_t nmemb, 2160c0d303SJoseph Huber ::FILE *stream)) { 2260c0d303SJoseph Huber 2360c0d303SJoseph Huber if (size == 0 || nmemb == 0) 2460c0d303SJoseph Huber return 0; 25b6bc9d72SGuillaume Chatelet auto result = 26b6bc9d72SGuillaume Chatelet reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->write_unlocked( 2760c0d303SJoseph Huber buffer, size * nmemb); 2860c0d303SJoseph Huber if (result.has_error()) 2960c0d303SJoseph Huber libc_errno = result.error; 3060c0d303SJoseph Huber 3160c0d303SJoseph Huber return result.value / size; 3260c0d303SJoseph Huber } 3360c0d303SJoseph Huber 34*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 35