fmtfd.c 508 B

12345678910111213141516171819202122232425262728293031
  1. #include <u.h>
  2. #include <libc.h>
  3. #include "fmtdef.h"
  4. /*
  5. * public routine for final flush of a formatting buffer
  6. * to a file descriptor; returns total char count.
  7. */
  8. int
  9. fmtfdflush(Fmt *f)
  10. {
  11. if(_fmtFdFlush(f) <= 0)
  12. return -1;
  13. return f->nfmt;
  14. }
  15. /*
  16. * initialize an output buffer for buffered printing
  17. */
  18. int
  19. fmtfdinit(Fmt *f, int fd, char *buf, int size)
  20. {
  21. f->runes = 0;
  22. f->start = buf;
  23. f->to = buf;
  24. f->stop = buf + size;
  25. f->flush = _fmtFdFlush;
  26. f->farg = (void*)fd;
  27. f->nfmt = 0;
  28. return 0;
  29. }