diff options
| author | Charles Forsyth <charles.forsyth@gmail.com> | 2013-06-06 20:59:23 +0000 |
|---|---|---|
| committer | Charles Forsyth <charles.forsyth@gmail.com> | 2013-06-06 20:59:23 +0000 |
| commit | 72335078034e3cd7edcb1739556b405a3e1e9bf8 (patch) | |
| tree | 9e1baa8ea80bfab1885cfcf224a62040a417fa74 /libbio/bputc.c | |
| parent | 3a0400887de9df81e4d4fb3bc3dec52af2d49f80 (diff) | |
sync with plan 9
Diffstat (limited to 'libbio/bputc.c')
| -rw-r--r-- | libbio/bputc.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/libbio/bputc.c b/libbio/bputc.c index 5f0fba59..d05badaa 100644 --- a/libbio/bputc.c +++ b/libbio/bputc.c @@ -4,26 +4,17 @@ int Bputc(Biobuf *bp, int c) { - int i, j; + int i; -loop: - i = bp->ocount; - j = i+1; - if(i != 0) { - bp->ocount = j; - bp->ebuf[i] = c; - return 0; + for(;;) { + i = bp->ocount; + if(i) { + bp->ebuf[i++] = c; + bp->ocount = i; + return 0; + } + if(Bflush(bp) == Beof) + break; } - if(bp->state != Bwactive) - return Beof; - j = write(bp->fid, bp->bbuf, bp->bsize); - if(j == bp->bsize) { - bp->ocount = -bp->bsize; - bp->offset += j; - goto loop; - } - fprint(2, "Bputc: write error\n"); - bp->state = Binactive; - bp->ocount = 0; return Beof; } |
