1e1c54d4dSMichael Jones //===-- FILE Writer implementation for printf -------------------*- C++ -*-===// 2e1c54d4dSMichael Jones // 3e1c54d4dSMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e1c54d4dSMichael Jones // See https://llvm.org/LICENSE.txt for license information. 5e1c54d4dSMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e1c54d4dSMichael Jones // 7e1c54d4dSMichael Jones //===----------------------------------------------------------------------===// 8e1c54d4dSMichael Jones 9e1c54d4dSMichael Jones #include "src/stdio/printf_core/file_writer.h" 10e1c54d4dSMichael Jones #include "src/__support/File/file.h" 11*9e421a16SMichael Jones #include "src/stdio/printf_core/core_structs.h" 12e1c54d4dSMichael Jones #include <stddef.h> 13e1c54d4dSMichael Jones 14e1c54d4dSMichael Jones namespace __llvm_libc { 15e1c54d4dSMichael Jones namespace printf_core { 16e1c54d4dSMichael Jones write(const char * __restrict to_write,size_t len)172e6eccfeSMichael Jonesint FileWriter::write(const char *__restrict to_write, size_t len) { 182e6eccfeSMichael Jones int written = file->write_unlocked(to_write, len); 19ad709a75SMichael Jones if (written != static_cast<int>(len)) 20*9e421a16SMichael Jones written = FILE_WRITE_ERROR; 212e6eccfeSMichael Jones if (file->error_unlocked()) 22*9e421a16SMichael Jones written = FILE_STATUS_ERROR; 232e6eccfeSMichael Jones return written; 242e6eccfeSMichael Jones } 252e6eccfeSMichael Jones write_to_file(void * raw_pointer,const char * __restrict to_write,size_t len)262e6eccfeSMichael Jonesint write_to_file(void *raw_pointer, const char *__restrict to_write, 27e1c54d4dSMichael Jones size_t len) { 282e6eccfeSMichael Jones FileWriter *file_writer = reinterpret_cast<FileWriter *>(raw_pointer); 292e6eccfeSMichael Jones return file_writer->write(to_write, len); 30e1c54d4dSMichael Jones } 31e1c54d4dSMichael Jones 32e1c54d4dSMichael Jones } // namespace printf_core 33e1c54d4dSMichael Jones } // namespace __llvm_libc 34