Tizen 2.1 base
[external/device-mapper.git] / lib / misc / crc_gen.c
1 /*
2  * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
3  *
4  * This file is part of LVM2.
5  *
6  * This copyrighted material is made available to anyone wishing to use,
7  * modify, copy, or redistribute it subject to the terms and conditions
8  * of the GNU Lesser General Public License v.2.1.
9  *
10  * You should have received a copy of the GNU Lesser General Public License
11  * along with this program; if not, write to the Free Software Foundation,
12  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
13  */
14
15 /*
16  * Helper program to generate table included in crc.c.
17  */
18 #include "lib.h"
19
20 int main(int argc, char **argv)
21 {
22         uint32_t crc, i, j;
23
24         printf("\t/* CRC-32 byte lookup table generated by crc_gen.c */\n");
25         printf("\tstatic const uint32_t crctab[] = {");
26
27         for (i = 0; i < 256; i++) {
28                 crc = i;
29                 for (j = 0; j < 8; j++) {
30                         if (crc & 1)
31                                 crc = 0xedb88320L ^ (crc >> 1);
32                         else
33                                 crc = crc >> 1;
34                 }
35
36                 if (i % 8)
37                         printf(" ");
38                 else
39                         printf("\n\t\t");
40
41                 printf("0x%08.8x,", crc);
42         }
43
44         printf("\n\t};\n");
45
46         return 0;
47 }