Date: Sun, 05 Mar 2017 22:43:38 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 217571] [Feature suggestion] make md5 print the checksum to stderr Message-ID: <bug-217571-8@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D217571 Bug ID: 217571 Summary: [Feature suggestion] make md5 print the checksum to stderr Product: Base System Version: 11.0-STABLE Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: manon@manon.de Hi,=20 the following patch patch adds option -P to md5/sha[1/256..] to print the digest to stderr when operating in filter mode. this is usefull when print= ing the digest while redirecting stdout. eg: sha512 -P < tarfile | tar -xf- -C /test/dir=20 hope this makes sense. Kind regards, Manon diff -ur /usr/src/sbin/md5/md5.1 ./md5.1 --- /usr/src/sbin/md5/md5.1 2016-10-15 22:19:31.346635000 +0200 +++ ./md5.1 2017-03-05 23:05:31.938946000 +0100 @@ -7,37 +7,37 @@ .Nd calculate a message-digest fingerprint (checksum) for a file .Sh SYNOPSIS .Nm md5 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar .Nm sha1 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar .Nm sha256 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar .Nm sha384 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar .Nm sha512 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar .Nm sha512t256 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar .Nm rmd160 -.Op Fl pqrtx +.Op Fl Ppqrtx .Op Fl c Ar string .Op Fl s Ar string .Op Ar @@ -109,6 +109,8 @@ .Ar string . .It Fl p Echo stdin to stdout and append the checksum to stdout. +.It Fl P +Echo stdin to stdout and write the checksum to stderr. .It Fl q Quiet mode \(em only the checksum is printed out. Overrides the diff -ur /usr/src/sbin/md5/md5.c ./md5.c --- /usr/src/sbin/md5/md5.c 2016-10-15 22:19:31.349312000 +0200 +++ ./md5.c 2017-03-05 23:07:54.742808000 +0100 @@ -176,7 +176,7 @@ failed =3D 0; checkAgainst =3D NULL; checksFailed =3D 0; - while ((ch =3D getopt(argc, argv, "c:pqrs:tx")) !=3D -1) + while ((ch =3D getopt(argc, argv, "c:Ppqrs:tx")) !=3D -1) switch (ch) { case 'c': checkAgainst =3D optarg; @@ -184,6 +184,9 @@ case 'p': MDFilter(&Algorithm[digest], 1); break; + case 'P': + MDFilter(&Algorithm[digest], 2); + break; case 'q': qflag =3D 1; break; @@ -456,6 +459,7 @@ { DIGEST_CTX context; unsigned int len; + FILE *filehandle; unsigned char buffer[BUFSIZ]; char buf[HEX_DIGEST_LENGTH]; @@ -465,13 +469,17 @@ err(1, "stdout"); alg->Update(&context, buffer, len); } - printf("%s\n", alg->End(&context, buf)); +=20=20=20=20=20=20=20 + filehandle =3D stdin; + if (tee > 1)=20 + filehandle =3D stderr; + fprintf(filehandle, "%s\n", alg->End(&context, buf)); } static void usage(const Algorithm_t *alg) { - fprintf(stderr, "usage: %s [-pqrtx] [-c string] [-s string] [files ...]\n", alg->progname); + fprintf(stderr, "usage: %s [-Ppqrtx] [-c string] [-s string] [files ...]\n", alg->progname); exit(1); } --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-217571-8>