zerotrunc.c 729 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * cat standard input until you get a zero byte
  11. */
  12. #include <u.h>
  13. #include <libc.h>
  14. void
  15. main(void)
  16. {
  17. char buf[4096];
  18. char *p;
  19. int n;
  20. while((n = read(0, buf, sizeof(buf))) > 0){
  21. p = memchr(buf, 0, n);
  22. if(p != nil)
  23. n = p-buf;
  24. if(n > 0)
  25. write(1, buf, n);
  26. if(p != nil)
  27. break;
  28. }
  29. exits(0);
  30. }