bvprint.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. static int
  13. fmtBflush(Fmt *f)
  14. {
  15. Biobufhdr *bp;
  16. bp = f->farg;
  17. bp->ocount = (char*)f->to - (char*)f->stop;
  18. if(Bflush(bp) < 0)
  19. return 0;
  20. f->stop = bp->ebuf;
  21. f->to = (char*)f->stop + bp->ocount;
  22. f->start = f->to;
  23. return 1;
  24. }
  25. int
  26. Bvprint(Biobufhdr *bp, char *fmt, va_list arg)
  27. {
  28. int n;
  29. Fmt f;
  30. f.runes = 0;
  31. f.stop = bp->ebuf;
  32. f.start = (char*)f.stop + bp->ocount;
  33. f.to = f.start;
  34. f.flush = fmtBflush;
  35. f.farg = bp;
  36. f.nfmt = 0;
  37. //f.args = arg;
  38. va_copy(f.args, arg);
  39. n = dofmt(&f, fmt);
  40. va_end(f.args);
  41. bp->ocount = (char*)f.to - (char*)f.stop;
  42. return n;
  43. }