Refactor cryptcheck() to allow multiple list-files and stdin
Previously, it was not possible to use sha1sum test.c | sha1sum -c because the program would not differenciate between an empty argument and a non-specified argument. Moreover, why not allow this? sha1sum -c hashlist1 hashlist2 Digging deeper I found that using function pointers and a modification in the crypt-backend might simplify the program a lot by passing the argument-list to both cryptmain and cryptcheck. Allowing more than one list-file to be specified is also consistent with what the other implementations support, so we not only have simpler code, we also do not silently break if there's a script around passing multiple files to check.
This commit is contained in:
10
md5sum.c
10
md5sum.c
@@ -24,20 +24,16 @@ usage(void)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int (*cryptfunc)(int, char **, struct crypt_ops *, uint8_t *, size_t) = cryptmain;
|
||||
uint8_t md[MD5_DIGEST_LENGTH];
|
||||
char *checkfile = NULL;
|
||||
int cflag = 0;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
checkfile = ARGF();
|
||||
cryptfunc = cryptcheck;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
||||
if (cflag)
|
||||
return cryptcheck(checkfile, argc, argv, &md5_ops, md, sizeof(md));
|
||||
return cryptmain(argc, argv, &md5_ops, md, sizeof(md));
|
||||
return cryptfunc(argc, argv, &md5_ops, md, sizeof(md));
|
||||
}
|
||||
|
Reference in New Issue
Block a user