aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/md5sum.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2014-11-17 11:21:06 -0500
committerRuss Cox <rsc@swtch.com>2014-11-17 11:21:06 -0500
commitc9ed52730b352448c7c644f6942d310dd3509bf6 (patch)
treed9723cd78c8b632e76e90f51ae43bd65c2139116 /src/cmd/md5sum.c
parent08e793723cad1c7aed2e8cb16c8592aba5ad05e9 (diff)
downloadplan9port-c9ed52730b352448c7c644f6942d310dd3509bf6.tar.gz
plan9port-c9ed52730b352448c7c644f6942d310dd3509bf6.tar.bz2
plan9port-c9ed52730b352448c7c644f6942d310dd3509bf6.zip
cmd: rename *.C to *.c
These were *.C back in 2003, before the 9 script, to avoid conflicts with the system utilities. A later change renamed them, but that change seems to have been lost during the hg->git conversion because I ran the conversion on a case-insensitive file system. Change-Id: Id32c99cb9571ef0e185c3cc9e8c8d6d5b48ca195
Diffstat (limited to 'src/cmd/md5sum.c')
-rw-r--r--src/cmd/md5sum.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/cmd/md5sum.c b/src/cmd/md5sum.c
new file mode 100644
index 00000000..8eabbf62
--- /dev/null
+++ b/src/cmd/md5sum.c
@@ -0,0 +1,61 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <libsec.h>
+
+static int
+digestfmt(Fmt *fmt)
+{
+ char buf[MD5dlen*2+1];
+ uchar *p;
+ int i;
+
+ p = va_arg(fmt->args, uchar*);
+ for(i=0; i<MD5dlen; i++)
+ sprint(buf+2*i, "%.2ux", p[i]);
+ return fmtstrcpy(fmt, buf);
+}
+
+static void
+sum(int fd, char *name)
+{
+ int n;
+ uchar buf[8192], digest[MD5dlen];
+ DigestState *s;
+
+ s = md5(nil, 0, nil, nil);
+ while((n = read(fd, buf, sizeof buf)) > 0)
+ md5(buf, n, nil, s);
+ md5(nil, 0, digest, s);
+ if(name == nil)
+ print("%M\n", digest);
+ else
+ print("%M\t%s\n", digest, name);
+}
+
+void
+main(int argc, char *argv[])
+{
+ int i, fd;
+
+ ARGBEGIN{
+ default:
+ fprint(2, "usage: md5sum [file...]\n");
+ exits("usage");
+ }ARGEND
+
+ fmtinstall('M', digestfmt);
+
+ if(argc == 0)
+ sum(0, nil);
+ else for(i = 0; i < argc; i++){
+ fd = open(argv[i], OREAD);
+ if(fd < 0){
+ fprint(2, "md5sum: can't open %s: %r\n", argv[i]);
+ continue;
+ }
+ sum(fd, argv[i]);
+ close(fd);
+ }
+ exits(nil);
+}