split loops by endian
This commit is contained in:
parent
58f9e4591e
commit
0226973efa
1 changed files with 18 additions and 10 deletions
28
main.c
28
main.c
|
@ -118,28 +118,36 @@ open_stream(char *filename)
|
||||||
return stream;
|
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
|
static uint32_t
|
||||||
cycle_file(FILE *stream)
|
cycle_file(FILE *stream)
|
||||||
{
|
{
|
||||||
uint32_t remainder = starting;
|
uint32_t remainder = starting;
|
||||||
typeof(&crc_be_cycle) cycle;
|
|
||||||
cycle = (big_endian) ? crc_be_cycle : crc_le_cycle;
|
|
||||||
uint32_t table[CRC_TABLE_SIZE];
|
uint32_t table[CRC_TABLE_SIZE];
|
||||||
|
|
||||||
if (big_endian)
|
if (big_endian)
|
||||||
crc_be_fill_table(table, polynomial);
|
crc_be_fill_table(table, polynomial);
|
||||||
else
|
else
|
||||||
crc_le_fill_table(table, polynomial);
|
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++)
|
if (big_endian) do {
|
||||||
cycle(table, &remainder, buff[i]);
|
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));
|
} while (!feof(stream));
|
||||||
|
|
||||||
if (xor_output)
|
if (xor_output)
|
||||||
|
|
Loading…
Add table
Reference in a new issue