tzerotrunc: from Plan 9 - plan9port - [fork] Plan 9 from user space (HTM) git clone git://src.adamsgaard.dk/plan9port (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit b6863de7e1b95fd68623e1a03eca6d3aebc4732e (DIR) parent f6d2cbfe4795015d252ef9c6d281adccf069438f (HTM) Author: David du Colombier <0intro@gmail.com> Date: Tue, 16 Aug 2011 16:11:56 -0400 zerotrunc: from Plan 9 R=rsc CC=plan9port.codebot http://codereview.appspot.com/4809089 Diffstat: A src/cmd/zerotrunc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+), 0 deletions(-) --- (DIR) diff --git a/src/cmd/zerotrunc.c b/src/cmd/zerotrunc.c t@@ -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); +} +