1 //===-- FILE Writer definition 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 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FILE_WRITER_H
10 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FILE_WRITER_H
11 
12 #include "src/__support/File/file.h"
13 
14 #include <stddef.h>
15 #include <stdio.h>
16 
17 namespace __llvm_libc {
18 namespace printf_core {
19 
20 class FileWriter {
21   __llvm_libc::File *file;
22 
23 public:
FileWriter(::FILE * init_file)24   FileWriter(::FILE *init_file) {
25     file = reinterpret_cast<__llvm_libc::File *>(init_file);
26     file->lock();
27   }
28 
~FileWriter()29   ~FileWriter() { file->unlock(); }
30 
31   int write(const char *__restrict to_write, size_t len);
32 };
33 
34 // write_to_file treats raw_pointer as a File and calls its write
35 // function.
36 int write_to_file(void *raw_pointer, const char *__restrict to_write,
37                   size_t len);
38 
39 } // namespace printf_core
40 } // namespace __llvm_libc
41 
42 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FILE_WRITER_H
43