From 23b406e176386f62cef07ec8c3dd5fae9b640dff Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Sun, 26 Feb 1995 01:55:31 +0000 Subject: [PATCH] Add a '-p' option to md5. This will save some time in generation of the ctm deltas. --- sbin/md5/md5.1 | 5 ++++- sbin/md5/md5.c | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1 index 2eb928044d95..153054a89046 100644 --- a/sbin/md5/md5.1 +++ b/sbin/md5/md5.1 @@ -3,7 +3,7 @@ md5 \- calculate a message-digest fingerprint (checksum) for a file .SH SYNOPSIS .B md5 -[ -t | -x | -sstring | filename(s) ] +[ -p | -t | -x | -sstring | filename(s) ] .SH DESCRIPTION .B md5 takes as input a message of arbitrary length and produces @@ -26,6 +26,9 @@ must be the last objects on the command line. .B -sstring prints a checksum of the given "string". .PP +.B -p +echos stdin to stdout and appends the MD5 sum to stdout. +.PP .B -t runs a built-in time trial. .PP diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c index afa8ef84aa48..72af3ebb9e0c 100644 --- a/sbin/md5/md5.c +++ b/sbin/md5/md5.c @@ -1,5 +1,5 @@ /* - * $Id$ + * $Id: md5.c,v 1.2 1995/02/20 00:48:50 phk Exp $ * * Derived from: */ @@ -36,7 +36,7 @@ static void MDString PROTO_LIST((char *)); static void MDTimeTrial PROTO_LIST((void)); static void MDTestSuite PROTO_LIST((void)); -static void MDFilter PROTO_LIST((void)); +static void MDFilter PROTO_LIST((int)); /* Main driver. @@ -61,6 +61,8 @@ main(argc, argv) MDString(argv[i] + 2); else if (strcmp(argv[i], "-t") == 0) MDTimeTrial(); + else if (strcmp(argv[i], "-p") == 0) + MDFilter(1); else if (strcmp(argv[i], "-x") == 0) MDTestSuite(); else { @@ -71,7 +73,7 @@ main(argc, argv) printf("MD5 (%s) = %s\n", argv[i], p); } else - MDFilter(); + MDFilter(0); return (0); } @@ -94,7 +96,7 @@ MDTimeTrial() { MD5_CTX context; time_t endTime, startTime; - unsigned char block[TEST_BLOCK_LEN], digest[16]; + unsigned char block[TEST_BLOCK_LEN]; unsigned int i; char *p; @@ -151,14 +153,17 @@ MDTestSuite() * Digests the standard input and prints the result. */ static void -MDFilter() +MDFilter(int pipe) { MD5_CTX context; int len; unsigned char buffer[BUFSIZ], digest[16]; MD5Init(&context); - while (len = fread(buffer, 1, BUFSIZ, stdin)) + while (len = fread(buffer, 1, BUFSIZ, stdin)) { + if(pipe && (len != fwrite(buffer, 1, len, stdout))) + perror(stdout); MD5Update(&context, buffer, len); + } printf("%s\n", MD5End(&context)); }