bflush.c 479 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. int
  5. Bflush(Biobufhdr *bp)
  6. {
  7. int n, c;
  8. switch(bp->state) {
  9. case Bwactive:
  10. n = bp->bsize+bp->ocount;
  11. if(n == 0)
  12. return 0;
  13. c = write(bp->fid, bp->bbuf, n);
  14. if(n == c) {
  15. bp->offset += n;
  16. bp->ocount = -bp->bsize;
  17. return 0;
  18. }
  19. bp->state = Binactive;
  20. bp->ocount = 0;
  21. break;
  22. case Bracteof:
  23. bp->state = Bractive;
  24. case Bractive:
  25. bp->icount = 0;
  26. bp->gbuf = bp->ebuf;
  27. return 0;
  28. }
  29. return Beof;
  30. }