1 //===- circular_raw_ostream.cpp - Implement circular_raw_ostream ----------===//
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
7 //===----------------------------------------------------------------------===//
9 // This implements support for circular buffered streams.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/circular_raw_ostream.h"
17 void circular_raw_ostream::write_impl(const char *Ptr
, size_t Size
) {
18 if (BufferSize
== 0) {
19 TheStream
->write(Ptr
, Size
);
23 // Write into the buffer, wrapping if necessary.
26 std::min(unsigned(Size
), unsigned(BufferSize
- (Cur
- BufferArray
)));
27 memcpy(Cur
, Ptr
, Bytes
);
30 if (Cur
== BufferArray
+ BufferSize
) {
31 // Reset the output pointer to the start of the buffer.
38 void circular_raw_ostream::flushBufferWithBanner() {
39 if (BufferSize
!= 0) {
40 // Write out the buffer
41 TheStream
->write(Banner
, std::strlen(Banner
));