~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to libclamav/7z/Delta.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Delta.c -- Delta converter
2
 
2009-05-26 : Igor Pavlov : Public domain */
3
 
 
4
 
#include "Delta.h"
5
 
 
6
 
void Delta_Init(Byte *state)
7
 
{
8
 
  unsigned i;
9
 
  for (i = 0; i < DELTA_STATE_SIZE; i++)
10
 
    state[i] = 0;
11
 
}
12
 
 
13
 
static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
14
 
{
15
 
  unsigned i;
16
 
  for (i = 0; i < size; i++)
17
 
    dest[i] = src[i];
18
 
}
19
 
 
20
 
void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
21
 
{
22
 
  Byte buf[DELTA_STATE_SIZE];
23
 
  unsigned j = 0;
24
 
  MyMemCpy(buf, state, delta);
25
 
  {
26
 
    SizeT i;
27
 
    for (i = 0; i < size;)
28
 
    {
29
 
      for (j = 0; j < delta && i < size; i++, j++)
30
 
      {
31
 
        Byte b = data[i];
32
 
        data[i] = (Byte)(b - buf[j]);
33
 
        buf[j] = b;
34
 
      }
35
 
    }
36
 
  }
37
 
  if (j == delta)
38
 
    j = 0;
39
 
  MyMemCpy(state, buf + j, delta - j);
40
 
  MyMemCpy(state + delta - j, buf, j);
41
 
}
42
 
 
43
 
void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
44
 
{
45
 
  Byte buf[DELTA_STATE_SIZE];
46
 
  unsigned j = 0;
47
 
  MyMemCpy(buf, state, delta);
48
 
  {
49
 
    SizeT i;
50
 
    for (i = 0; i < size;)
51
 
    {
52
 
      for (j = 0; j < delta && i < size; i++, j++)
53
 
      {
54
 
        buf[j] = data[i] = (Byte)(buf[j] + data[i]);
55
 
      }
56
 
    }
57
 
  }
58
 
  if (j == delta)
59
 
    j = 0;
60
 
  MyMemCpy(state, buf + j, delta - j);
61
 
  MyMemCpy(state + delta - j, buf, j);
62
 
}
 
1
/* Delta.c -- Delta converter
 
2
2009-05-26 : Igor Pavlov : Public domain */
 
3
 
 
4
#include "Delta.h"
 
5
 
 
6
void Delta_Init(Byte *state)
 
7
{
 
8
  unsigned i;
 
9
  for (i = 0; i < DELTA_STATE_SIZE; i++)
 
10
    state[i] = 0;
 
11
}
 
12
 
 
13
static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
 
14
{
 
15
  unsigned i;
 
16
  for (i = 0; i < size; i++)
 
17
    dest[i] = src[i];
 
18
}
 
19
 
 
20
void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
 
21
{
 
22
  Byte buf[DELTA_STATE_SIZE];
 
23
  unsigned j = 0;
 
24
  MyMemCpy(buf, state, delta);
 
25
  {
 
26
    SizeT i;
 
27
    for (i = 0; i < size;)
 
28
    {
 
29
      for (j = 0; j < delta && i < size; i++, j++)
 
30
      {
 
31
        Byte b = data[i];
 
32
        data[i] = (Byte)(b - buf[j]);
 
33
        buf[j] = b;
 
34
      }
 
35
    }
 
36
  }
 
37
  if (j == delta)
 
38
    j = 0;
 
39
  MyMemCpy(state, buf + j, delta - j);
 
40
  MyMemCpy(state + delta - j, buf, j);
 
41
}
 
42
 
 
43
void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
 
44
{
 
45
  Byte buf[DELTA_STATE_SIZE];
 
46
  unsigned j = 0;
 
47
  MyMemCpy(buf, state, delta);
 
48
  {
 
49
    SizeT i;
 
50
    for (i = 0; i < size;)
 
51
    {
 
52
      for (j = 0; j < delta && i < size; i++, j++)
 
53
      {
 
54
        buf[j] = data[i] = (Byte)(buf[j] + data[i]);
 
55
      }
 
56
    }
 
57
  }
 
58
  if (j == delta)
 
59
    j = 0;
 
60
  MyMemCpy(state, buf + j, delta - j);
 
61
  MyMemCpy(state + delta - j, buf, j);
 
62
}