1 /* tee - pipe fitting Author: Paul Polderman */
8 #include <minix/minlib.h>
11 #define CHUNK_SIZE 4096
15 int main(int argc
, char **argv
);
21 char iflag
= 0, aflag
= 0;
27 while (argc
> 0 && argv
[0][0] == '-') {
29 case 'i': /* Interrupt turned off. */
32 case 'a': /* Append to outputfile(s), instead of
33 * overwriting them. */
37 std_err("Usage: tee [-i] [-a] [files].\n");
43 fd
[0] = 1; /* Always output to stdout. */
44 for (s
= 1; s
< MAXFD
&& argc
> 0; --argc
, argv
++, s
++) {
45 if (aflag
&& (fd
[s
] = open(*argv
, O_RDWR
)) >= 0) {
46 lseek(fd
[s
], 0L, SEEK_END
);
49 if ((fd
[s
] = creat(*argv
, 0666)) >= 0) continue;
51 std_err("Cannot open output file: ");
57 if (iflag
) signal(SIGINT
, SIG_IGN
);
59 while ((n
= read(0, buf
, CHUNK_SIZE
)) > 0) {
60 for (i
= 0; i
< s
; i
++) write(fd
[i
], buf
, n
);
63 for (i
= 0; i
< s
; i
++) /* Close all fd's */