[hackers] [sbase] tee: Make sure we continue on error || sin

From: <git_AT_suckless.org>
Date: Thu, 23 Jun 2016 20:38:11 +0200 (CEST)

commit 11d8e91042de565fa4ab81f2c8bf6aef14ded0e5
Author: sin <sin_AT_2f30.org>
AuthorDate: Thu Jun 23 19:37:23 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Thu Jun 23 19:38:05 2016 +0100

    tee: Make sure we continue on error

diff --git a/tee.c b/tee.c
index 399824c..35e3db5 100644
--- a/tee.c
+++ b/tee.c
_AT_@ -34,20 +34,28 @@ main(int argc, char *argv[])
         nfps = argc + 1;
         fps = ecalloc(nfps, sizeof(*fps));
 
- for (i = 0; i < argc; i++)
- if (!(fps[i] = fopen(argv[i], aflag ? "a" : "w")))
- eprintf("fopen %s:", argv[i]);
+ for (i = 0; i < argc; i++) {
+ if (!(fps[i] = fopen(argv[i], aflag ? "a" : "w"))) {
+ weprintf("fopen %s:", argv[i]);
+ ret = 1;
+ }
+ }
         fps[i] = stdout;
 
         while ((n = fread(buf, 1, sizeof(buf), stdin))) {
                 for (i = 0; i < nfps; i++) {
- if (fwrite(buf, 1, n, fps[i]) == n)
- continue;
- eprintf("fwrite %s:", (i != argc) ? argv[i] : "<stdout>");
+ if (fps[i] && fwrite(buf, 1, n, fps[i]) != n) {
+ fshut(fps[i], (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;
 }
Received on Thu Jun 23 2016 - 20:38:11 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 23 2016 - 20:48:16 CEST