mirror of
https://codeberg.org/landley/toybox.git
synced 2026-01-26 06:07:55 +00:00
Bugfix: tee with no arguments was writing to stdout twice.
Add basic smoketest while we're at it.
This commit is contained in:
parent
058471577a
commit
f3d4a2c72f
9
tests/tee.test
Executable file
9
tests/tee.test
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "" "tee" "one" "" "one"
|
||||
testing "" "tee -" "two\n" "" "two\n"
|
||||
testing "" "tee one > two && cmp one two && echo that" "that\n" "" "three"
|
||||
@ -54,18 +54,18 @@ void tee_main(void)
|
||||
|
||||
for (;;) {
|
||||
struct fd_list *fdl;
|
||||
int len;
|
||||
int len, out = 0;
|
||||
|
||||
// Read data from stdin
|
||||
len = xread(0, toybuf, sizeof(toybuf));
|
||||
if (len<1) break;
|
||||
|
||||
// Write data to each output file, plus stdout.
|
||||
fdl = TT.outputs;
|
||||
for (;;) {
|
||||
if(len != writeall(fdl ? fdl->fd : 1, toybuf, len)) toys.exitval=1;
|
||||
for (fdl = TT.outputs; ;fdl = fdl->next) {
|
||||
if (!fdl && out) break;
|
||||
if (len != writeall(fdl ? fdl->fd : 1, toybuf, len)) toys.exitval=1;
|
||||
if (!fdl) break;
|
||||
fdl = fdl->next;
|
||||
if (fdl->fd == 1) out++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user