diff --git a/crc32.c b/crc32.c index fa2d770..6e0ebb1 100644 --- a/crc32.c +++ b/crc32.c @@ -1,9 +1,9 @@ enum { CRC_TABLE_SIZE = 0x100 }; -ulong -crc_reflect(ulong input) +uint32_t +crc_reflect(uint32_t input) { - ulong reflected = 0; + uint32_t reflected = 0; for (int i = 0; i < 4 * 8; i++) { reflected <<= 1; reflected |= input & 1; @@ -13,10 +13,10 @@ crc_reflect(ulong input) } void -crc_fill_table(ulong *table, int big, ulong polynomial) +crc_fill_table(uint32_t *table, int big, uint32_t polynomial) { - ulong lsb = (big) ? 1 << 31 : 1; /* least significant bit */ - ulong poly = (big) ? polynomial : crc_reflect(polynomial); + uint32_t lsb = (big) ? 1 << 31 : 1; /* least significant bit */ + uint32_t poly = (big) ? polynomial : crc_reflect(polynomial); for (int c = 0; c < CRC_TABLE_SIZE; c++, table++) { *table = (big) ? c << 24 : c; @@ -33,15 +33,15 @@ crc_fill_table(ulong *table, int big, ulong polynomial) } void -crc_be_cycle(ulong *table, ulong *remainder, char c) +crc_be_cycle(uint32_t *table, uint32_t *remainder, char c) { - ulong byte = table[(((*remainder) >> 24) ^ c) & 0xff]; + uint32_t byte = table[(((*remainder) >> 24) ^ c) & 0xff]; *remainder = (((*remainder) << 8) ^ byte) & 0xFFFFFFFF; } void -crc_le_cycle(ulong *table, ulong *remainder, char c) +crc_le_cycle(uint32_t *table, uint32_t *remainder, char c) { - ulong byte = table[((*remainder) ^ c) & 0xFF]; + uint32_t byte = table[((*remainder) ^ c) & 0xFF]; *remainder = ((*remainder) >> 8) ^ byte; } diff --git a/main.c b/main.c index 9c10dc4..6ca39b4 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,6 @@ #include #include - -typedef unsigned long ulong; +#include #include "crc32.c" #include "args.c" @@ -19,9 +18,9 @@ struct string_node_s { static string_node *input_node = NULL; -static ulong starting = 0xFFFFFFFF; +static uint32_t starting = 0xFFFFFFFF; static char big_endian = 0; -static ulong polynomial = 0x04C11DB7; +static uint32_t polynomial = 0x04C11DB7; static char print_binary = 0; static char xor_output = 1; static char reflect_output = 0; @@ -118,13 +117,13 @@ open_stream(char *filename) } -static ulong +static uint32_t cycle_file(FILE *stream) { - ulong remainder = starting; - void (*cycle)(ulong*, ulong*, char) = + uint32_t remainder = starting; + void (*cycle)(uint32_t*, uint32_t*, char) = (big_endian) ? crc_be_cycle : crc_le_cycle; - ulong table[CRC_TABLE_SIZE]; + uint32_t table[CRC_TABLE_SIZE]; crc_fill_table(table, big_endian, polynomial); do { @@ -146,7 +145,7 @@ cycle_file(FILE *stream) } static void -print_crc(ulong remainder) +print_crc(uint32_t remainder) { if (print_binary) fwrite(&remainder, sizeof(remainder), 1, stdout);