bflush.c (525B) download
1#include "common.h"
2#include "lib9.h"
3
4#include <bio.h>
5
6int Bflush(Biobuf* bp) {
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 FALLTHROUGH;
27
28 case Bractive:
29 bp->icount = 0;
30 bp->gbuf = bp->ebuf;
31 return 0;
32 }
33 return Beof;
34}