44 lines
829 B
C
Raw Normal View History

2015-06-04 21:20:25 +02:00
/* gcc -O3 -o crc32 crc32.c -lz */
#include <stdio.h>
#include <errno.h>
#include <string.h>
2016-09-21 12:33:42 +02:00
#include <encodings/crc32.h>
2015-06-04 21:26:40 +02:00
int main(int argc, const char* argv[])
2015-06-04 21:20:25 +02:00
{
2015-06-04 21:26:40 +02:00
if (argc != 2 )
{
fprintf( stderr, "Usage: crc32 <filename>\n" );
return 1;
}
FILE *file = fopen(argv[1], "rb");
if (file)
{
2016-09-21 12:35:38 +02:00
uint32_t crc = encoding_crc32(0L, NULL, 0 );
2015-06-04 21:26:40 +02:00
for (;;)
2015-06-04 21:20:25 +02:00
{
2016-09-21 12:35:38 +02:00
uint8_t buffer[16384];
2015-06-04 21:26:40 +02:00
int numread = fread((void*)buffer, 1, sizeof(buffer), file);
if (numread > 0)
2016-09-21 12:33:42 +02:00
crc = encoding_crc32( crc, buffer, numread );
2015-06-04 21:26:40 +02:00
else
break;
2015-06-04 21:20:25 +02:00
}
2015-06-04 21:26:40 +02:00
fclose(file);
printf("%08x\n", crc);
return 0;
}
fprintf(stderr, "Error opening input file: %s\n", strerror(errno));
return 1;
2015-06-04 21:20:25 +02:00
}