fmtfd.c 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "fmtdef.h"
  12. /*
  13. * public routine for final flush of a formatting buffer
  14. * to a file descriptor; returns total char count.
  15. */
  16. int
  17. fmtfdflush(Fmt *f)
  18. {
  19. if(_fmtFdFlush(f) <= 0)
  20. return -1;
  21. return f->nfmt;
  22. }
  23. /*
  24. * initialize an output buffer for buffered printing
  25. */
  26. int
  27. fmtfdinit(Fmt *f, int fd, char *buf, int size)
  28. {
  29. f->runes = 0;
  30. f->start = buf;
  31. f->to = buf;
  32. f->stop = buf + size;
  33. f->flush = _fmtFdFlush;
  34. f->farg = (void*)(uintptr_t)fd;
  35. f->nfmt = 0;
  36. return 0;
  37. }