1 //===-- Implementation of fwrite and fwrite_unlocked ------------*- C++ -*-===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/stdio/fwrite.h" 10 #include "src/stdio/FILE.h" 11 #include "src/threads/mtx_lock.h" 12 #include "src/threads/mtx_unlock.h" 13 14 namespace __llvm_libc { 15 16 size_t fwrite_unlocked(const void *__restrict ptr, size_t size, size_t nmeb, 17 __llvm_libc::FILE *__restrict stream) { 18 return stream->write(stream, reinterpret_cast<const char *>(ptr), 19 size * nmeb); 20 } 21 22 size_t fwrite(const void *__restrict ptr, size_t size, size_t nmeb, 23 __llvm_libc::FILE *__restrict stream) { 24 __llvm_libc::mtx_lock(&stream->lock); 25 size_t written = fwrite_unlocked(ptr, size, nmeb, stream); 26 __llvm_libc::mtx_unlock(&stream->lock); 27 return written; 28 } 29 30 } // namespace __llvm_libc 31