summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/md5/md5.112
-rw-r--r--sbin/md5/md5.c29
2 files changed, 36 insertions, 5 deletions
diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1
index 7fb415fd0717..c485184cc440 100644
--- a/sbin/md5/md5.1
+++ b/sbin/md5/md5.1
@@ -1,3 +1,4 @@
+.\" $FreeBSD$
.Dd February 14, 1994
.Dt MD5 1
.Os
@@ -6,7 +7,7 @@
.Nd calculate a message-digest fingerprint (checksum) for a file
.Sh SYNOPSIS
.Nm md5
-.Op Fl ptx
+.Op Fl pqrtx
.Op Fl s Ar string
.Op Ar file ...
.Sh DESCRIPTION
@@ -37,6 +38,15 @@ Print a checksum of the given
.Ar string .
.It Fl p
Echo stdin to stdout and appends the MD5 sum to stdout.
+.It Fl q
+Quiet mode - only the MD5 sum is printed out. Overrides the
+.Fl r
+option.
+.It Fl r
+Reverses the format of the output. This helps with visual diffs. Does nothing
+when combined with the
+.Fl ptx
+options.
.It Fl t
Run a built-in time trial.
.It Fl x
diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c
index d4b287e3fd63..9a764b120bee 100644
--- a/sbin/md5/md5.c
+++ b/sbin/md5/md5.c
@@ -28,6 +28,7 @@ static const char rcsid[] =
#include <stdio.h>
#include <time.h>
#include <unistd.h>
+#include <string.h>
#include "global.h"
@@ -37,6 +38,9 @@ static const char rcsid[] =
#define TEST_BLOCK_LEN 10000
#define TEST_BLOCK_COUNT 100000
+int qflag;
+int rflag;
+
static void MDString PROTO_LIST((char *));
static void MDTimeTrial PROTO_LIST((void));
static void MDTestSuite PROTO_LIST((void));
@@ -62,11 +66,17 @@ main(argc, argv)
char buf[33];
if (argc > 1) {
- while ((ch = getopt(argc, argv, "ps:tx")) != -1) {
+ while ((ch = getopt(argc, argv, "ps:qrtx")) != -1) {
switch (ch) {
case 'p':
MDFilter(1);
break;
+ case 'q':
+ qflag = 1;
+ break;
+ case 'r':
+ rflag = 1;
+ break;
case 's':
MDString(optarg);
break;
@@ -85,7 +95,13 @@ main(argc, argv)
if (!p)
warn("%s", argv[optind]);
else
- printf("MD5 (%s) = %s\n", argv[optind], p);
+ if (qflag)
+ printf("%s\n", p);
+ else if (rflag)
+ printf("%s %s\n", p, argv[optind]);
+ else
+ printf("MD5 (%s) = %s\n", argv[optind],
+ p);
optind++;
}
} else
@@ -100,10 +116,15 @@ static void
MDString(string)
char *string;
{
- unsigned int len = strlen(string);
+ size_t len = strlen(string);
char buf[33];
- printf("MD5 (\"%s\") = %s\n", string, MD5Data(string, len, buf));
+ if (qflag)
+ printf("%s\n", MD5Data(string, len, buf));
+ else if (rflag)
+ printf("%s \"%s\"\n", MD5Data(string, len, buf), string);
+ else
+ printf("MD5 (\"%s\") = %s\n", string, MD5Data(string, len, buf));
}
/*
* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.