zerotrunc.c 318 B

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