tee.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* David Korn
* AT&T Bell Laboratories
*
* tee
*/
static const char usage[] =
"[-?\n@(#)$Id: tee (AT&T Research) 2006-10-10 $\n]"
"[+NAME?tee - duplicate standard input]"
"[+DESCRIPTION?\btee\b copies standard input to standard output "
"and to zero or more files. The options determine whether "
"the specified files are overwritten or appended to. The "
"\btee\b utility does not buffer output. If writes to any "
"\afile\a fail, writes to other files continue although \btee\b "
"will exit with a non-zero exit status.]"
"[+?The number of \afile\a operands that can be specified is limited "
"by the underlying operating system.]"
"[a:append?Append the standard input to the given files rather "
"than overwriting them.]"
"[i:ignore-interrupts?Ignore SIGINT signal.]"
"[l:linebuffer?Set the standard output to be line buffered.]"
"\n"
"\n[file ...]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?All files copies successfully.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bcat\b(1), \bsignal\b(3)]"
;
#include <cmd.h>
#include <ls.h>
#include <sig.h>
typedef struct Tee_s
{
int fd[1];
} Tee_t;
/*
* This discipline writes to each file in the list given in handle
*/
{
register const char* bp;
register const char* ep;
register ssize_t r;
do
{
{
return(-1);
bp += r;
}
return(n);
}
int
{
register int n;
register int* hp;
register char* cp;
int line;
line = -1;
{
case 'a':
break;
case 'i':
break;
case 'l':
line = -1;
else
break;
case ':':
break;
case '?':
break;
}
if(error_info.errors)
/*
* for backward compatibility
*/
{
argv++;
argc--;
}
if (argc > 0)
{
{
else hp++;
}
tp = 0;
else
{
*hp = -1;
}
}
/*
* close files and free resources
*/
if (tp)
{
if (line >= 0)
close(n);
}
return(error_info.errors);
}