* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1988 Regents of the University of California.\n\
static char sccsid
[] = "@(#)tee.c 5.9 (Berkeley) %G%";
extern int errno
, optind
;
register int n
, fd
, rval
, wval
;
char *buf
, *malloc(), *strerror();
while ((ch
= getopt(argc
, argv
, "ai")) != EOF
)
(void)signal(SIGINT
, SIG_IGN
);
(void)fprintf(stderr
, "usage: tee [-ai] [file ...]\n");
if (!(buf
= malloc((u_int
)8 * 1024))) {
(void)fprintf(stderr
, "tee: out of space.\n");
add(STDOUT_FILENO
, "stdout");
if ((fd
= open(*argv
, append
? O_WRONLY
|O_CREAT
|O_APPEND
:
O_WRONLY
|O_CREAT
|O_TRUNC
, 0600)) < 0)
(void)fprintf(stderr
, "tee: %s: %s.\n",
while ((rval
= read(STDIN_FILENO
, buf
, sizeof(buf
))) > 0)
for (p
= head
; p
; p
= p
->next
) {
if ((wval
= write(p
->fd
, bp
, n
)) == -1) {
(void)fprintf(stderr
, "tee: %s: %s.\n",
p
->name
, strerror(errno
));
(void)fprintf(stderr
, "tee: read: %s\n", strerror(errno
));
char *malloc(), *strerror();
if (!(p
= (LIST
*)malloc((u_int
)sizeof(LIST
)))) {
(void)fprintf(stderr
, "tee: out of space.\n");