1 //===-- 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 #include "writer.h" 10 #include "src/string/memory_utils/memset_implementations.h" 11 #include <stddef.h> 12 13 namespace __llvm_libc { 14 namespace printf_core { 15 16 int Writer::write(const char *new_string, size_t length) { 17 chars_written += length; 18 return raw_write(output, new_string, length); 19 } 20 21 int Writer::write_chars(char new_char, size_t length) { 22 constexpr size_t BUFF_SIZE = 8; 23 char buff[BUFF_SIZE]; 24 int result; 25 inline_memset(buff, new_char, BUFF_SIZE); 26 while (length > BUFF_SIZE) { 27 result = write(buff, BUFF_SIZE); 28 if (result < 0) 29 return result; 30 length -= BUFF_SIZE; 31 } 32 return write(buff, length); 33 } 34 35 } // namespace printf_core 36 } // namespace __llvm_libc 37