1 //===-- FILE Writer implementation for printf -------------------*- 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/printf_core/file_writer.h"
10 #include "src/__support/File/file.h"
11 #include "src/stdio/printf_core/core_structs.h"
12 #include <stddef.h>
13 
14 namespace __llvm_libc {
15 namespace printf_core {
16 
write(const char * __restrict to_write,size_t len)17 int FileWriter::write(const char *__restrict to_write, size_t len) {
18   int written = file->write_unlocked(to_write, len);
19   if (written != static_cast<int>(len))
20     written = FILE_WRITE_ERROR;
21   if (file->error_unlocked())
22     written = FILE_STATUS_ERROR;
23   return written;
24 }
25 
write_to_file(void * raw_pointer,const char * __restrict to_write,size_t len)26 int write_to_file(void *raw_pointer, const char *__restrict to_write,
27                   size_t len) {
28   FileWriter *file_writer = reinterpret_cast<FileWriter *>(raw_pointer);
29   return file_writer->write(to_write, len);
30 }
31 
32 } // namespace printf_core
33 } // namespace __llvm_libc
34