File: uac_crc.c

package info (click to toggle)
unace 1.2b-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 276 kB
  • ctags: 308
  • sloc: ansic: 1,709; sh: 113; makefile: 87
file content (38 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ------------------------------------------------------------------------ */
/*                                                                          */
/*      CRC-calculation routines.                                           */
/*                                                                          */
/* ------------------------------------------------------------------------ */
/*  ML - 01/2004: changed licence to GPL                                    */
/* ------------------------------------------------------------------------ */

#include "uac_crc.h"


ULONG crctable[256];
ULONG rd_crc=0;


void make_crctable(void)   // initializes CRC table
{
   ULONG r,
        i,
        j;

   for (i = 0; i <= 255; i++)
   {
      for (r = i, j = 8; j; j--)
         r = (r & 1) ? (r >> 1) ^ CRCPOLY : (r >> 1);
      crctable[i] = r;
   }
}

// Updates crc from addr till addr+len-1
//
ULONG getcrc(ULONG crc, UCHAR * addr, INT len)
{
   while (len--)
      crc = crctable[(unsigned char) crc ^ (*addr++)] ^ (crc >> 8);
   return (crc);
}