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 +#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); +} +