plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

zerotrunc.c (317B)


      1 /*
      2  * cat standard input until you get a zero byte
      3  */
      4 
      5 #include <u.h>
      6 #include <libc.h>
      7 
      8 void
      9 main(void)
     10 {
     11 	char buf[4096];
     12 	char *p;
     13 	int n;
     14 
     15 	while((n = read(0, buf, sizeof(buf))) > 0){
     16 		p = memchr(buf, 0, n);
     17 		if(p != nil)
     18 			n = p-buf;
     19 		if(n > 0)
     20 			write(1, buf, n);
     21 		if(p != nil)
     22 			break;
     23 	}
     24 	exits(0);
     25 }