1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 5 int 6 Bputc(Biobufhdr *bp, int c) 7 { 8 int i, j; 9 10 loop: 11 i = bp->ocount; 12 j = i+1; 13 if(i != 0) { 14 bp->ocount = j; 15 bp->ebuf[i] = c; 16 return 0; 17 } 18 if(bp->state != Bwactive) 19 return Beof; 20 j = write(bp->fid, bp->bbuf, bp->bsize); 21 if(j == bp->bsize) { 22 bp->ocount = -bp->bsize; 23 bp->offset += j; 24 goto loop; 25 } 26 fprint(2, "Bputc: write error\n"); 27 bp->state = Binactive; 28 bp->ocount = 0; 29 return Beof; 30 } 31