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