bvprint.c 584 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. static int
  5. fmtBflush(Fmt *f)
  6. {
  7. Biobufhdr *bp;
  8. bp = f->farg;
  9. bp->ocount = (char*)f->to - (char*)f->stop;
  10. if(Bflush(bp) < 0)
  11. return 0;
  12. f->stop = bp->ebuf;
  13. f->to = (char*)f->stop + bp->ocount;
  14. f->start = f->to;
  15. return 1;
  16. }
  17. int
  18. Bvprint(Biobufhdr *bp, char *fmt, va_list arg)
  19. {
  20. int n;
  21. Fmt f;
  22. f.runes = 0;
  23. f.stop = bp->ebuf;
  24. f.start = (char*)f.stop + bp->ocount;
  25. f.to = f.start;
  26. f.flush = fmtBflush;
  27. f.farg = bp;
  28. f.nfmt = 0;
  29. f.args = arg;
  30. n = dofmt(&f, fmt);
  31. bp->ocount = (char*)f.to - (char*)f.stop;
  32. return n;
  33. }