Support reading checksums from stdin
This commit is contained in:
parent
9ad5ca5a15
commit
c323f6f233
7
md5sum.c
7
md5sum.c
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -25,16 +26,18 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t md[MD5_DIGEST_LENGTH];
|
uint8_t md[MD5_DIGEST_LENGTH];
|
||||||
char *checkfile = NULL;
|
char *checkfile = NULL;
|
||||||
|
bool cflag = false;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'c':
|
case 'c':
|
||||||
checkfile = EARGF(usage());
|
cflag = true;
|
||||||
|
checkfile = ARGF();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if(checkfile)
|
if(cflag)
|
||||||
return cryptcheck(checkfile, argc, argv, &md5_ops, md, sizeof(md));
|
return cryptcheck(checkfile, argc, argv, &md5_ops, md, sizeof(md));
|
||||||
return cryptmain(argc, argv, &md5_ops, md, sizeof(md));
|
return cryptmain(argc, argv, &md5_ops, md, sizeof(md));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -25,16 +26,18 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t md[SHA1_DIGEST_LENGTH];
|
uint8_t md[SHA1_DIGEST_LENGTH];
|
||||||
char *checkfile = NULL;
|
char *checkfile = NULL;
|
||||||
|
bool cflag = false;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'c':
|
case 'c':
|
||||||
checkfile = EARGF(usage());
|
cflag = true;
|
||||||
|
checkfile = ARGF();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if(checkfile)
|
if(cflag)
|
||||||
return cryptcheck(checkfile, argc, argv, &sha1_ops, md, sizeof(md));
|
return cryptcheck(checkfile, argc, argv, &sha1_ops, md, sizeof(md));
|
||||||
return cryptmain(argc, argv, &sha1_ops, md, sizeof(md));
|
return cryptmain(argc, argv, &sha1_ops, md, sizeof(md));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -25,16 +26,18 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t md[SHA256_DIGEST_LENGTH];
|
uint8_t md[SHA256_DIGEST_LENGTH];
|
||||||
char *checkfile = NULL;
|
char *checkfile = NULL;
|
||||||
|
bool cflag = false;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'c':
|
case 'c':
|
||||||
checkfile = EARGF(usage());
|
cflag = true;
|
||||||
|
checkfile = ARGF();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if(checkfile)
|
if(cflag)
|
||||||
return cryptcheck(checkfile, argc, argv, &sha256_ops, md, sizeof(md));
|
return cryptcheck(checkfile, argc, argv, &sha256_ops, md, sizeof(md));
|
||||||
return cryptmain(argc, argv, &sha256_ops, md, sizeof(md));
|
return cryptmain(argc, argv, &sha256_ops, md, sizeof(md));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -25,16 +26,18 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t md[SHA512_DIGEST_LENGTH];
|
uint8_t md[SHA512_DIGEST_LENGTH];
|
||||||
char *checkfile = NULL;
|
char *checkfile = NULL;
|
||||||
|
bool cflag = false;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'c':
|
case 'c':
|
||||||
checkfile = EARGF(usage());
|
cflag = true;
|
||||||
|
checkfile = ARGF();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if(checkfile)
|
if(cflag)
|
||||||
return cryptcheck(checkfile, argc, argv, &sha512_ops, md, sizeof(md));
|
return cryptcheck(checkfile, argc, argv, &sha512_ops, md, sizeof(md));
|
||||||
return cryptmain(argc, argv, &sha512_ops, md, sizeof(md));
|
return cryptmain(argc, argv, &sha512_ops, md, sizeof(md));
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,9 @@ cryptcheck(char *sumfile, int argc, char *argv[],
|
||||||
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = EXIT_SUCCESS;
|
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = EXIT_SUCCESS;
|
||||||
size_t bufsiz = 0;
|
size_t bufsiz = 0;
|
||||||
|
|
||||||
if(!(cfp = fopen(sumfile, "r")))
|
if(sumfile == NULL)
|
||||||
|
cfp = stdin;
|
||||||
|
else if(!(cfp = fopen(sumfile, "r")))
|
||||||
eprintf("fopen %s:", sumfile);
|
eprintf("fopen %s:", sumfile);
|
||||||
|
|
||||||
while(afgets(&line, &bufsiz, cfp)) {
|
while(afgets(&line, &bufsiz, cfp)) {
|
||||||
|
@ -78,6 +80,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
if(sumfile != NULL)
|
||||||
fclose(cfp);
|
fclose(cfp);
|
||||||
free(line);
|
free(line);
|
||||||
if(formatsucks > 0) {
|
if(formatsucks > 0) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user