* Copyright (c) 1985 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1985 Regents of the University of California.\n\
static char *sccsid
= "@(#)tee.c 5.2 (Berkeley) %G%";
register FILE **openf
, **lastf
, **fdp
;
char buf
[8192], *calloc();
while (argc
> 0 && argv
[0][0] == '-') {
lastf
= openf
= (FILE **)calloc(argc
+1, sizeof (FILE *));
fprintf(stderr
, "tee: Out of memory.\n");
*lastf
++ = stdout
; /* default */
for (; argc
> 0; argc
--, argv
++) {
*lastf
= fopen(argv
[0], aflag
? "a" : "w");
fprintf(stderr
, "tee: %s: cannot open.\n", argv
[0]);
while ((cc
= fread(buf
, 1, sizeof (buf
), stdin
)) > 0)
for (fdp
= openf
; fdp
< lastf
; fdp
++)
fwrite(buf
, 1, cc
, *fdp
);