diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-12-21 05:12:56 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-12-21 05:12:56 +0100 |
commit | 127f8f048047e03d74001c4bbd50b7c0c09d7c0e (patch) | |
tree | 43bdb957dfab63d2fc8d49f498b2c8df92cde9e0 /sys/src/cmd/tee.c | |
parent | 468851cde6d0a2c160f1d4beec49ca11eb5506c1 (diff) |
tee: get rid of openf[100] array and just dup() filedescriptors to 3+[0..n-1]
Diffstat (limited to 'sys/src/cmd/tee.c')
-rw-r--r-- | sys/src/cmd/tee.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/sys/src/cmd/tee.c b/sys/src/cmd/tee.c index 83db8a08f..40a3171fa 100644 --- a/sys/src/cmd/tee.c +++ b/sys/src/cmd/tee.c @@ -5,9 +5,12 @@ #include <u.h> #include <libc.h> +enum { + FDSTART = 3, +}; + int uflag; int aflag; -int openf[100]; char in[8192]; @@ -42,26 +45,29 @@ main(int argc, char **argv) n = 0; while(*argv) { if(aflag) { - openf[n] = open(argv[0], OWRITE); - if(openf[n] < 0) - openf[n] = create(argv[0], OWRITE, 0666); - seek(openf[n], 0L, 2); + i = open(argv[0], OWRITE); + if(i < 0) + i = create(argv[0], OWRITE, 0666); + seek(i, 0L, 2); } else - openf[n] = create(argv[0], OWRITE, 0666); - if(openf[n] < 0) { + i = create(argv[0], OWRITE, 0666); + if(i < 0) { fprint(2, "tee: cannot open %s: %r\n", argv[0]); - } else + } else { + if(i != n+FDSTART) + dup(i, n+FDSTART); n++; + } argv++; } - openf[n++] = 1; for(;;) { r = read(0, in, sizeof in); if(r <= 0) exits(nil); for(i=0; i<n; i++) - write(openf[i], in, r); + write(i+FDSTART, in, r); + write(1, in, r); } } |