crypt: error status code if an error occured in a file series

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-03-23 12:30:34 +01:00 committed by sin
parent 7727530b53
commit 18b6e40161

View File

@ -10,6 +10,7 @@ cryptmain(int argc, char *argv[],
struct crypt_ops *ops, uint8_t *md, size_t sz) struct crypt_ops *ops, uint8_t *md, size_t sz)
{ {
FILE *fp; FILE *fp;
int ret = EXIT_SUCCESS;
if (argc == 0) { if (argc == 0) {
cryptsum(ops, stdin, "<stdin>", md); cryptsum(ops, stdin, "<stdin>", md);
@ -18,15 +19,18 @@ cryptmain(int argc, char *argv[],
for (; argc > 0; argc--) { for (; argc > 0; argc--) {
if((fp = fopen(*argv, "r")) == NULL) { if((fp = fopen(*argv, "r")) == NULL) {
weprintf("fopen %s:", *argv); weprintf("fopen %s:", *argv);
ret = EXIT_FAILURE;
continue; continue;
} }
cryptsum(ops, fp, *argv, md); if(cryptsum(ops, fp, *argv, md) == 1)
ret = EXIT_FAILURE;
else
mdprint(md, *argv, sz); mdprint(md, *argv, sz);
fclose(fp); fclose(fp);
argv++; argv++;
} }
} }
return EXIT_SUCCESS; return ret;
} }
int int
@ -40,7 +44,7 @@ cryptsum(struct crypt_ops *ops, FILE *fp, const char *f,
while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) while ((n = fread(buf, 1, sizeof(buf), fp)) > 0)
ops->update(ops->s, buf, n); ops->update(ops->s, buf, n);
if (ferror(fp)) { if (ferror(fp)) {
eprintf("read error: %s:", f); weprintf("read error: %s:", f);
return 1; return 1;
} }
ops->sum(ops->s, md); ops->sum(ops->s, md);