Display error messages where appropriate in checksum utilities.

This commit is contained in:
Stephen Heumann 2017-11-19 23:30:13 -06:00
parent b5b268982a
commit 0475dbf132

View File

@ -38,12 +38,16 @@ int main(int argc, char **argv) {
srand(time(NULL));
if (argc != 2)
if (argc != 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]);
return EXIT_FAILURE;
}
file = fopen(argv[1], "rb");
if (file == NULL)
if (file == NULL) {
perror(argv[1]);
return EXIT_FAILURE;
}
concat(HASH_FUNCTION,_init)(&ctx);
do {
@ -56,6 +60,10 @@ int main(int argc, char **argv) {
concat(HASH_FUNCTION,_update)(&ctx, buf, count);
} while (count != 0);
if (ferror(file)) {
fprintf(stderr, "Error reading file\n");
}
fclose(file);
concat(HASH_FUNCTION,_finalize)(&ctx);