lcd-m6sp.c: remove \r
[kugel-rb.git] / apps / codecs / libmusepack / crc32.c
blob7613f1c2c85a2b67c380b61537887fc0cddba77b
1 /*
2 * C Implementation: crc32
4 * code from http://www.w3.org/TR/PNG/#D-CRCAppendix
6 */
7 #include "internal.h"
9 /* Table of CRCs of all 8-bit messages. */
10 static unsigned long crc_table[256];
12 /* Flag: has the table been computed? Initially false. */
13 static int crc_table_computed = 0;
15 /* Make the table for a fast CRC. */
16 static void make_crc_table(void)
18 unsigned long c;
19 int n, k;
21 for (n = 0; n < 256; n++) {
22 c = (unsigned long) n;
23 for (k = 0; k < 8; k++) {
24 if (c & 1)
25 c = 0xedb88320L ^ (c >> 1);
26 else
27 c = c >> 1;
29 crc_table[n] = c;
31 crc_table_computed = 1;
35 /* Update a running CRC with the bytes buf[0..len-1]--the CRC
36 should be initialized to all 1's, and the transmitted value
37 is the 1's complement of the final running CRC (see the
38 crc() routine below). */
40 static unsigned long update_crc(unsigned long crc, unsigned char *buf, int len)
42 unsigned long c = crc;
43 int n;
45 if (!crc_table_computed)
46 make_crc_table();
47 for (n = 0; n < len; n++) {
48 c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
50 return c;
53 /* Return the CRC of the bytes buf[0..len-1]. */
54 unsigned long mpc_crc32(unsigned char *buf, int len)
56 return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;