~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Support/circular_raw_ostream.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//===- circular_raw_ostream.cpp - Implement circular_raw_ostream ----------===//
2
 
//
3
 
//                     The LLVM Compiler Infrastructure
4
 
//
5
 
// This file is distributed under the University of Illinois Open Source
6
 
// License. See LICENSE.TXT for details.
7
 
//
8
 
//===----------------------------------------------------------------------===//
9
 
//
10
 
// This implements support for circular buffered streams.
11
 
//
12
 
//===----------------------------------------------------------------------===//
13
 
 
14
 
#include "llvm/Support/circular_raw_ostream.h"
15
 
#include <algorithm>
16
 
using namespace llvm;
17
 
 
18
 
void circular_raw_ostream::write_impl(const char *Ptr, size_t Size) {
19
 
  if (BufferSize == 0) {
20
 
    TheStream->write(Ptr, Size);
21
 
    return;
22
 
  }
23
 
 
24
 
  // Write into the buffer, wrapping if necessary.
25
 
  while (Size != 0) {
26
 
    unsigned Bytes =
27
 
      std::min(unsigned(Size), unsigned(BufferSize - (Cur - BufferArray)));
28
 
    memcpy(Cur, Ptr, Bytes);
29
 
    Size -= Bytes;
30
 
    Cur += Bytes;
31
 
    if (Cur == BufferArray + BufferSize) {
32
 
      // Reset the output pointer to the start of the buffer.
33
 
      Cur = BufferArray;
34
 
      Filled = true;
35
 
    }
36
 
  }    
37
 
}
38
 
 
39
 
void circular_raw_ostream::flushBufferWithBanner() {
40
 
  if (BufferSize != 0) {
41
 
    // Write out the buffer
42
 
    TheStream->write(Banner, std::strlen(Banner));
43
 
    flushBuffer();
44
 
  }
45
 
}