aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/zerotrunc.c
blob: 2ff1d53f190876b4ca801e93529093df11a8e2f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * 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);
}