aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/tee.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-11-23 18:04:47 +0000
committerrsc <devnull@localhost>2003-11-23 18:04:47 +0000
commitbc7cb1a15a67c859c8c71c4b52bb35fe9425a63d (patch)
tree8ca0fe4e2418e6aa18dc74a236c577a719f6c6ed /src/cmd/tee.c
parentf08fdedcee12c06e3ce9ac9bec363915978e8289 (diff)
downloadplan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.gz
plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.bz2
plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.zip
new utilities.
the .C files compile but are renamed to avoid building automatically.
Diffstat (limited to 'src/cmd/tee.c')
-rw-r--r--src/cmd/tee.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/cmd/tee.c b/src/cmd/tee.c
new file mode 100644
index 00000000..83db8a08
--- /dev/null
+++ b/src/cmd/tee.c
@@ -0,0 +1,75 @@
+/*
+ * tee-- pipe fitting
+ */
+
+#include <u.h>
+#include <libc.h>
+
+int uflag;
+int aflag;
+int openf[100];
+
+char in[8192];
+
+int intignore(void*, char*);
+
+void
+main(int argc, char **argv)
+{
+ int i;
+ int r, n;
+
+ ARGBEGIN {
+ case 'a':
+ aflag++;
+ break;
+
+ case 'i':
+ atnotify(intignore, 1);
+ break;
+
+ case 'u':
+ uflag++;
+ /* uflag is ignored and undocumented; it's a relic from Unix */
+ break;
+
+ default:
+ fprint(2, "usage: tee [-ai] [file ...]\n");
+ exits("usage");
+ } ARGEND
+
+ USED(argc);
+ n = 0;
+ while(*argv) {
+ if(aflag) {
+ openf[n] = open(argv[0], OWRITE);
+ if(openf[n] < 0)
+ openf[n] = create(argv[0], OWRITE, 0666);
+ seek(openf[n], 0L, 2);
+ } else
+ openf[n] = create(argv[0], OWRITE, 0666);
+ if(openf[n] < 0) {
+ fprint(2, "tee: cannot open %s: %r\n", argv[0]);
+ } else
+ n++;
+ argv++;
+ }
+ openf[n++] = 1;
+
+ for(;;) {
+ r = read(0, in, sizeof in);
+ if(r <= 0)
+ exits(nil);
+ for(i=0; i<n; i++)
+ write(openf[i], in, r);
+ }
+}
+
+int
+intignore(void *a, char *msg)
+{
+ USED(a);
+ if(strcmp(msg, "interrupt") == 0)
+ return 1;
+ return 0;
+}