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 <stddef.h>
12 
13 namespace __llvm_libc {
14 namespace printf_core {
15 
16 int FileWriter::write(const char *__restrict to_write, size_t len) {
17   int written = file->write_unlocked(to_write, len);
18   if (written != len)
19     written = -1;
20   if (file->error_unlocked())
21     written = -2;
22   return written;
23 }
24 
25 int write_to_file(void *raw_pointer, const char *__restrict to_write,
26                   size_t len) {
27   FileWriter *file_writer = reinterpret_cast<FileWriter *>(raw_pointer);
28   return file_writer->write(to_write, len);
29 }
30 
31 } // namespace printf_core
32 } // namespace __llvm_libc
33