1e072a123SMichael Jones //===-- Writer definition for printf ----------------------------*- C++ -*-===//
2e072a123SMichael Jones //
3e072a123SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e072a123SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5e072a123SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e072a123SMichael Jones //
7e072a123SMichael Jones //===----------------------------------------------------------------------===//
8e072a123SMichael Jones 
9e072a123SMichael Jones #include "writer.h"
10e072a123SMichael Jones #include "src/string/memory_utils/memset_implementations.h"
11e072a123SMichael Jones #include <stddef.h>
12e072a123SMichael Jones 
13e072a123SMichael Jones namespace __llvm_libc {
14e072a123SMichael Jones namespace printf_core {
15e072a123SMichael Jones 
write(const char * new_string,size_t length)16*2e6eccfeSMichael Jones int Writer::write(const char *new_string, size_t length) {
17e072a123SMichael Jones   chars_written += length;
18*2e6eccfeSMichael Jones   return raw_write(output, new_string, length);
19e072a123SMichael Jones }
20e072a123SMichael Jones 
write_chars(char new_char,size_t length)21*2e6eccfeSMichael Jones int Writer::write_chars(char new_char, size_t length) {
22e072a123SMichael Jones   constexpr size_t BUFF_SIZE = 8;
23e072a123SMichael Jones   char buff[BUFF_SIZE];
24*2e6eccfeSMichael Jones   int result;
25e072a123SMichael Jones   inline_memset(buff, new_char, BUFF_SIZE);
26e072a123SMichael Jones   while (length > BUFF_SIZE) {
27*2e6eccfeSMichael Jones     result = write(buff, BUFF_SIZE);
28*2e6eccfeSMichael Jones     if (result < 0)
29*2e6eccfeSMichael Jones       return result;
30e072a123SMichael Jones     length -= BUFF_SIZE;
31e072a123SMichael Jones   }
32*2e6eccfeSMichael Jones   return write(buff, length);
33e072a123SMichael Jones }
34e072a123SMichael Jones 
35e072a123SMichael Jones } // namespace printf_core
36e072a123SMichael Jones } // namespace __llvm_libc
37