~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/7z/7zBuf2.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-01 11:06:17 UTC
  • mfrom: (0.35.37 sid)
  • Revision ID: package-import@ubuntu.com-20140201110617-33h2xxk09dep0ui4
Tags: 0.98.1+dfsg-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Add autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 7zBuf2.c -- Byte Buffer
 
2
2008-10-04 : Igor Pavlov : Public domain */
 
3
 
 
4
#include <string.h>
 
5
#include "7zBuf.h"
 
6
 
 
7
void DynBuf_Construct(CDynBuf *p)
 
8
{
 
9
  p->data = 0;
 
10
  p->size = 0;
 
11
  p->pos = 0;
 
12
}
 
13
 
 
14
void DynBuf_SeekToBeg(CDynBuf *p)
 
15
{
 
16
  p->pos = 0;
 
17
}
 
18
 
 
19
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
 
20
{
 
21
  if (size > p->size - p->pos)
 
22
  {
 
23
    size_t newSize = p->pos + size;
 
24
    Byte *data;
 
25
    newSize += newSize / 4;
 
26
    data = (Byte *)alloc->Alloc(alloc, newSize);
 
27
    if (data == 0)
 
28
      return 0;
 
29
    p->size = newSize;
 
30
    memcpy(data, p->data, p->pos);
 
31
    alloc->Free(alloc, p->data);
 
32
    p->data = data;
 
33
  }
 
34
  memcpy(p->data + p->pos, buf, size);
 
35
  p->pos += size;
 
36
  return 1;
 
37
}
 
38
 
 
39
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
 
40
{
 
41
  alloc->Free(alloc, p->data);
 
42
  p->data = 0;
 
43
  p->size = 0;
 
44
  p->pos = 0;
 
45
}