tee: Make sure we continue on error
This commit is contained in:
parent
0ba879cdba
commit
11d8e91042
22
tee.c
22
tee.c
|
@ -34,20 +34,28 @@ main(int argc, char *argv[])
|
||||||
nfps = argc + 1;
|
nfps = argc + 1;
|
||||||
fps = ecalloc(nfps, sizeof(*fps));
|
fps = ecalloc(nfps, sizeof(*fps));
|
||||||
|
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++) {
|
||||||
if (!(fps[i] = fopen(argv[i], aflag ? "a" : "w")))
|
if (!(fps[i] = fopen(argv[i], aflag ? "a" : "w"))) {
|
||||||
eprintf("fopen %s:", argv[i]);
|
weprintf("fopen %s:", argv[i]);
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
fps[i] = stdout;
|
fps[i] = stdout;
|
||||||
|
|
||||||
while ((n = fread(buf, 1, sizeof(buf), stdin))) {
|
while ((n = fread(buf, 1, sizeof(buf), stdin))) {
|
||||||
for (i = 0; i < nfps; i++) {
|
for (i = 0; i < nfps; i++) {
|
||||||
if (fwrite(buf, 1, n, fps[i]) == n)
|
if (fps[i] && fwrite(buf, 1, n, fps[i]) != n) {
|
||||||
continue;
|
fshut(fps[i], (i != argc) ? argv[i] : "<stdout>");
|
||||||
eprintf("fwrite %s:", (i != argc) ? argv[i] : "<stdout>");
|
fps[i] = NULL;
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");
|
ret |= fshut(stdin, "<stdin>");
|
||||||
|
for (i = 0; i < nfps; i++)
|
||||||
|
if (fps[i])
|
||||||
|
ret |= fshut(fps[i], (i != argc) ? argv[i] : "<stdout>");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user