plan9port

[fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port # fast
git clone https://src.adamsgaard.dk/plan9port.git # slow
Log | Files | Refs | README | LICENSE Back to index

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 }