split loops by endian

This commit is contained in:
Connor Olding 2015-04-11 11:21:46 -07:00
parent 58f9e4591e
commit 0226973efa
1 changed files with 18 additions and 10 deletions

28
main.c
View File

@ -118,28 +118,36 @@ open_stream(char *filename)
return stream;
}
static inline size_t
buff_read(FILE *stream)
{
size_t len = fread(buff, 1, BUFFER_SIZE, stream);
if (ferror(stream)) {
perror(NULL);
exit(1);
}
return len;
}
static uint32_t
cycle_file(FILE *stream)
{
uint32_t remainder = starting;
typeof(&crc_be_cycle) cycle;
cycle = (big_endian) ? crc_be_cycle : crc_le_cycle;
uint32_t table[CRC_TABLE_SIZE];
if (big_endian)
crc_be_fill_table(table, polynomial);
else
crc_le_fill_table(table, polynomial);
do {
int len = fread(buff, 1, BUFFER_SIZE, stream);
if (ferror(stream)) {
perror(NULL);
exit(1);
}
for (int i = 0; i < len; i++)
cycle(table, &remainder, buff[i]);
if (big_endian) do {
size_t len = buff_read(stream);
for (size_t i = 0; i < len; i++)
crc_be_cycle(table, &remainder, buff[i]);
} while (!feof(stream)); else do {
size_t len = buff_read(stream);
for (size_t i = 0; i < len; i++)
crc_le_cycle(table, &remainder, buff[i]);
} while (!feof(stream));
if (xor_output)