aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/zerotrunc.c
diff options
context:
space:
mode:
authorDavid du Colombier <0intro@gmail.com>2011-08-16 16:11:56 -0400
committerRuss Cox <rsc@swtch.com>2011-08-16 16:11:56 -0400
commitb6863de7e1b95fd68623e1a03eca6d3aebc4732e (patch)
tree8e2d0ef599c6dfcccb242710fffab79ee3ab7d1a /src/cmd/zerotrunc.c
parentf6d2cbfe4795015d252ef9c6d281adccf069438f (diff)
downloadplan9port-b6863de7e1b95fd68623e1a03eca6d3aebc4732e.tar.gz
plan9port-b6863de7e1b95fd68623e1a03eca6d3aebc4732e.tar.bz2
plan9port-b6863de7e1b95fd68623e1a03eca6d3aebc4732e.zip
zerotrunc: from Plan 9
R=rsc CC=plan9port.codebot http://codereview.appspot.com/4809089
Diffstat (limited to 'src/cmd/zerotrunc.c')
-rw-r--r--src/cmd/zerotrunc.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/cmd/zerotrunc.c b/src/cmd/zerotrunc.c
new file mode 100644
index 00000000..ce6fafea
--- /dev/null
+++ b/src/cmd/zerotrunc.c
@@ -0,0 +1,26 @@
+/*
+ * cat standard input until you get a zero byte
+ */
+
+#include <u.h>
+#include <libc.h>
+
+void
+main(void)
+{
+ char buf[4096];
+ char *p;
+ int n;
+
+ while((n = read(0, buf, sizeof(buf))) > 0){
+ p = memchr(buf, 0, n);
+ if(p != nil)
+ n = p-buf;
+ if(n > 0)
+ write(1, buf, n);
+ if(p != nil)
+ break;
+ }
+ exits(0);
+}
+