1 /* tee - pipe fitting Author: Paul Polderman */
10 #include <minix/minlib.h>
15 #define CHUNK_SIZE 4096
19 _PROTOTYPE(int main
, (int argc
, char **argv
));
25 char iflag
= 0, aflag
= 0;
31 while (argc
> 0 && argv
[0][0] == '-') {
33 case 'i': /* Interrupt turned off. */
36 case 'a': /* Append to outputfile(s), instead of
37 * overwriting them. */
41 fprintf(stderr
,"Usage: tee [-i] [-a] [files].\n");
47 fd
[0] = 1; /* Always output to stdout. */
48 for (s
= 1; s
< MAXFD
&& argc
> 0; --argc
, argv
++, s
++) {
49 if (aflag
&& (fd
[s
] = open(*argv
, O_RDWR
)) >= 0) {
50 lseek(fd
[s
], 0L, SEEK_END
);
53 if ((fd
[s
] = creat(*argv
, 0666)) >= 0) continue;
55 fprintf(stderr
,"Cannot open output file: ");
56 fprintf(stderr
,*argv
);
61 if (iflag
) signal(SIGINT
, SIG_IGN
);
63 while ((n
= read(0, buf
, CHUNK_SIZE
)) > 0) {
64 for (i
= 0; i
< s
; i
++) write(fd
[i
], buf
, n
);
67 for (i
= 0; i
< s
; i
++) /* Close all fd's */