Allow checksumming multiple files, and print filenames with the checksums.

This commit is contained in:
Stephen Heumann 2017-11-19 23:41:05 -06:00
parent 0475dbf132
commit e288a7bc83

View File

@ -34,18 +34,19 @@ int main(int argc, char **argv) {
struct concat(HASH_FUNCTION,_context) ctx; struct concat(HASH_FUNCTION,_context) ctx;
FILE *file; FILE *file;
size_t count; size_t count;
int i; int i, n;
srand(time(NULL)); srand(time(NULL));
if (argc != 2) { if (argc < 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]); fprintf(stderr, "Usage: %s filename ...\n", argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
file = fopen(argv[1], "rb"); for (n = 1; n < argc; n++) {
file = fopen(argv[n], "rb");
if (file == NULL) { if (file == NULL) {
perror(argv[1]); perror(argv[n]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -70,7 +71,8 @@ int main(int argc, char **argv) {
for (i = 0; i < sizeof(ctx.hash); i++) { for (i = 0; i < sizeof(ctx.hash); i++) {
printf("%02x", ctx.hash[i]); printf("%02x", ctx.hash[i]);
} }
printf("\n"); printf(" %s\n", argv[n]);
}
return 0; return 0;
} }