/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* 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) 2012-05-31 $\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 line;
} Tee_t;
/*
* This discipline writes to each file in the list given in handle
*/
static ssize_t
{
register const char* bp;
register const char* ep;
register ssize_t r;
do
{
{
return -1;
bp += r;
}
return n;
}
static void
{
register int* hp;
register int n;
if (tp)
{
close(n);
}
}
int
{
register int* hp;
register char* cp;
int line;
if (argc <= 0)
{
{
}
return 0;
}
line = -1;
for (;;)
{
{
case 'a':
continue;
case 'i':
continue;
case 'l':
line = -1;
else
continue;
case ':':
break;
case '?':
break;
}
break;
}
if (error_info.errors)
{
argv++;
argc--;
}
#endif
if (argc > 0)
{
{
if (context)
{
while ((*hp = open(cp, oflag, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0 && errno == EINTR)
errno = 0;
if (*hp < 0)
else
hp++;
}
tp = 0;
else
{
*hp = -1;
}
}
else
}
if ((sfmove(sfstdin, sfstdout, SF_UNBOUND, -1) < 0 || !sfeof(sfstdin)) && !ERROR_PIPE(errno) && errno != EINTR)
return error_info.errors;
}