sum, md5sum, sha1sum: set exit status properly on open/read errors
This commit is contained in:
parent
026c679f49
commit
d73c67660b
3 changed files with 27 additions and 19 deletions
|
@ -7,6 +7,8 @@
|
|||
|
||||
#pragma varargck type "M" uchar*
|
||||
|
||||
static char exitstr[ERRMAX];
|
||||
|
||||
typedef struct Sha2 Sha2;
|
||||
struct Sha2 {
|
||||
int bits;
|
||||
|
@ -48,7 +50,8 @@ sum(int fd, char *name)
|
|||
while((n = read(fd, buf, sizeof buf)) > 0)
|
||||
(*shafunc)(buf, n, nil, s);
|
||||
if(n < 0){
|
||||
fprint(2, "reading %s: %r\n", name? name: "stdin");
|
||||
snprint(exitstr, sizeof(exitstr), "reading %s: %r\n", name? name: "stdin");
|
||||
fprint(2, "%s", exitstr);
|
||||
return;
|
||||
}
|
||||
(*shafunc)(nil, 0, digest, s);
|
||||
|
@ -96,11 +99,12 @@ main(int argc, char *argv[])
|
|||
for(i = 0; i < argc; i++){
|
||||
fd = open(argv[i], OREAD);
|
||||
if(fd < 0){
|
||||
fprint(2, "%s: can't open %s: %r\n", argv0, argv[i]);
|
||||
snprint(exitstr, sizeof(exitstr), "can't open %s: %r", argv[i]);
|
||||
fprint(2, "%s: %s\n", argv0, exitstr);
|
||||
continue;
|
||||
}
|
||||
sum(fd, argv[i]);
|
||||
close(fd);
|
||||
}
|
||||
exits(nil);
|
||||
exits(exitstr);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue