added small file-crc32'ing tool
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401314
This commit is contained in:
parent
4b75dffe41
commit
ad1173a318
2
tools/crc32/build.sh
Executable file
2
tools/crc32/build.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
g++ -I../../core ../../core/sm_crc32.cpp main.cpp -ocrc32
|
||||||
|
|
46
tools/crc32/main.cpp
Normal file
46
tools/crc32/main.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sm_crc32.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: crc32 <file>\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *fp = fopen(argv[1], "rb");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Could not open file: %s\n", argv[1]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
size_t size = ftell(fp);
|
||||||
|
if (!size)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Cannot checksum an empty file.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
|
void *buffer = malloc(size);
|
||||||
|
if (!buffer)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Unable to allocate %d bytes of memory.\n", size);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fread(buffer, size, 1, fp);
|
||||||
|
unsigned int crc32 = UTIL_CRC32(buffer, size);
|
||||||
|
free(buffer);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fprintf(stdout, "%08X\n", crc32);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user