]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libbio/bflush.c
merging erik quanstros nupas
[plan9front.git] / sys / src / libbio / bflush.c
1 #include        <u.h>
2 #include        <libc.h>
3 #include        <bio.h>
4
5 int
6 Bflush(Biobufhdr *bp)
7 {
8         int n, c;
9
10         switch(bp->state) {
11         case Bwactive:
12                 n = bp->bsize+bp->ocount;
13                 if(n == 0)
14                         return 0;
15                 c = write(bp->fid, bp->bbuf, n);
16                 if(n == c) {
17                         bp->offset += n;
18                         bp->ocount = -bp->bsize;
19                         return 0;
20                 }
21                 bp->state = Binactive;
22                 bp->ocount = 0;
23                 Berror(bp, "write error: %r");
24                 break;
25
26         case Bracteof:
27                 bp->state = Bractive;
28
29         case Bractive:
30                 bp->icount = 0;
31                 bp->gbuf = bp->ebuf;
32                 return 0;
33         }
34         return Beof;
35 }