From e09ef41f4fff3a8480ccd6bc60064de593daa8de Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sun, 8 Aug 2010 17:58:55 +0200 Subject: [PATCH] Add crc32 test program --- bacula/src/lib/crc32.c | 58 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/bacula/src/lib/crc32.c b/bacula/src/lib/crc32.c index dd2e71e273..eaee98606a 100644 --- a/bacula/src/lib/crc32.c +++ b/bacula/src/lib/crc32.c @@ -32,7 +32,6 @@ * */ - #ifdef GENERATE_STATIC_CRC_TABLE /* * The following code can be used to generate the static CRC table. @@ -138,3 +137,60 @@ uint32_t bcrc32(uint8_t *buf, int len) } return crc ^ 0xFFFFFFFFL; } + + + +#ifdef CRC32_SUM + +static void usage() +{ + fprintf(stderr, +"\n" +"Usage: crc32 \n" +" -? print this message.\n" +"\n\n"); + + exit(1); +} + +/* + * Reads a single ASCII file and prints the HEX md5 sum. + */ +#include +int main(int argc, char *argv[]) +{ + FILE *fd; + char buf[5000]; + int ch; + + while ((ch = getopt(argc, argv, "h?")) != -1) { + switch (ch) { + case 'h': + case '?': + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) { + printf("Must have filename\n"); + exit(1); + } + + fd = fopen(argv[0], "rb"); + if (!fd) { + printf("Could not open %s: ERR=%s\n", argv[0], strerror(errno)); + exit(1); + } + uint32_t res; + while (fgets(buf, sizeof(buf), fd)) { + res = bcrc32((unsigned char *)buf, strlen(buf)); + printf("%02x\n", res); + } + printf(" %s (old)\n", argv[0]); + fclose(fd); +} +#endif -- 2.39.5