#include "gbos.h" /* tee FILE: copy stdin to stdout AND to FILE. The missing half of a pipeline: * `cat big | tee copy | wc -l` keeps the data and counts it in one pass. */ void main(void) { char *argv[4]; unsigned char argc = argv_parse(argv, 4); unsigned char fd = NOFD; char c; if (argc > 0) { fd = open(argv[0], O_WRITE); if (fd > 3) { puts("tee: cannot create "); puts(argv[0]); nl(); sexit(2); } } for (;;) { c = readc(); if (c == EOF) break; putc(c); if (fd != NOFD) fputc(fd, c); } if (fd != NOFD) close(fd); }