commit b6863de7e1b95fd68623e1a03eca6d3aebc4732e from: David du Colombier <0intro@gmail.com> via: Russ Cox date: Tue Aug 16 20:11:56 2011 UTC zerotrunc: from Plan 9 R=rsc CC=plan9port.codebot http://codereview.appspot.com/4809089 commit - f6d2cbfe4795015d252ef9c6d281adccf069438f commit + b6863de7e1b95fd68623e1a03eca6d3aebc4732e blob - /dev/null blob + ce6fafeac782fdff559963b14e6d2c9a27906135 (mode 644) --- /dev/null +++ src/cmd/zerotrunc.c @@ -0,0 +1,26 @@ +/* + * cat standard input until you get a zero byte + */ + +#include +#include + +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); +} +