circular_raw_ostream.cpp [plain text]
#include "llvm/Support/circular_raw_ostream.h"
#include <algorithm>
using namespace llvm;
void circular_raw_ostream::write_impl(const char *Ptr, size_t Size) {
if (BufferSize == 0) {
TheStream->write(Ptr, Size);
return;
}
while (Size != 0) {
unsigned Bytes =
std::min(unsigned(Size), unsigned(BufferSize - (Cur - BufferArray)));
memcpy(Cur, Ptr, Bytes);
Size -= Bytes;
Cur += Bytes;
if (Cur == BufferArray + BufferSize) {
Cur = BufferArray;
Filled = true;
}
}
}
void circular_raw_ostream::flushBufferWithBanner() {
if (BufferSize != 0) {
TheStream->write(Banner, std::strlen(Banner));
flushBuffer();
}
}