summaryrefslogtreecommitdiff
path: root/lib/misc/crc_gen.c
blob: 56f2d25a9c3858304c4bca77ed242613e17fb386 (plain)
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
39
40
41
42
43
44
45
46
47
/*
 * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
 *
 * This file is part of LVM2.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License v.2.1.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * Helper program to generate table included in crc.c.
 */
#include "lib/misc/lib.h"

int main(int argc, char **argv)
{
	uint32_t crc, i, j;

	printf("\t/* CRC-32 byte lookup table generated by crc_gen.c */\n");
	printf("\tstatic const uint32_t crctab[] = {");

	for (i = 0; i < 256; i++) {
		crc = i;
		for (j = 0; j < 8; j++) {
			if (crc & 1)
				crc = 0xedb88320L ^ (crc >> 1);
			else
				crc = crc >> 1;
		}

		if (i % 8)
			printf(" ");
		else
			printf("\n\t\t");

		printf("0x%08.8x,", crc);
	}

	printf("\n\t};\n");

	return 0;
}