1 /* tee.c - cat to multiple outputs.
3 * Copyright 2008 Rob Landley <rob@landley.net>
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/tee.html
7 USE_TEE(NEWTOY(tee, "ia", TOYFLAG_USR|TOYFLAG_BIN))
13 usage: tee [-ai] [file...]
15 Copy stdin to each listed file, and also to stdout.
16 Filename "-" is a synonym for stdout.
34 // Open each output file, saving filehandles to a linked list.
36 static void do_tee_open(int fd, char *name)
40 temp = xmalloc(sizeof(struct fd_list));
41 temp->next = TT.outputs;
48 if (toys.optflags & FLAG_i) xsignal(SIGINT, SIG_IGN);
51 loopfiles_rw(toys.optargs,
52 O_RDWR|O_CREAT|WARN_ONLY|((toys.optflags & FLAG_a)?O_APPEND:O_TRUNC),
59 // Read data from stdin
60 len = xread(0, toybuf, sizeof(toybuf));
63 // Write data to each output file, plus stdout.
66 if(len != writeall(fdl ? fdl->fd : 1, toybuf, len)) toys.exitval=1;