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 void Writer::write(const char *new_string, size_t length) { 17 18 raw_write(output, new_string, length); 19 20 // chars_written tracks the number of chars that would have been written 21 // regardless of what the raw_write call does. 22 chars_written += length; 23 } 24 25 void Writer::write_chars(char new_char, size_t length) { 26 constexpr size_t BUFF_SIZE = 8; 27 char buff[BUFF_SIZE]; 28 inline_memset(buff, new_char, BUFF_SIZE); 29 while (length > BUFF_SIZE) { 30 write(buff, BUFF_SIZE); 31 length -= BUFF_SIZE; 32 } 33 write(buff, length); 34 } 35 36 } // namespace printf_core 37 } // namespace __llvm_libc 38