/*
* fc32.c - A sample program for the use with fast CRC-32 routines.
* It calculates the CRC-32 of a file.
*
* Copyright 1999 G. Adam Stanislav.
* All rights reserved.
*/
#include <stdio.h>
#include "crc32.h"
#define BUFFERSIZE 1024
unsigned char buffer[BUFFERSIZE];
int main(int argc, char *argv[]) {
FILE *file;
unsigned int crc = initcrc32();
if (argc > 2) {
fprintf(stderr, "FC32 Usage: fc32 [file]\n");
return 1;
}
if (argc == 2) {
file = fopen(argv[1], "r");
if (file == NULL) {
fprintf(stderr, "FC32: Can't open %s\n", argv[1]);
return 2;
}
}
else
file = stdin;
while (!feof(file))
crc = partialcrc32(crc,
buffer,
fread(buffer,
sizeof(unsigned char),
BUFFERSIZE,
file));
if (file != stdin)
fclose(file);
printf("CRC-32 = %08x\n", finishcrc32(crc));
return 0;
}