aboutsummaryrefslogtreecommitdiff
path: root/libbio/bwrite.c
diff options
context:
space:
mode:
authorbhgv <bhgv.empire@gmail.com>2018-03-01 16:54:45 +0200
committerbhgv <bhgv.empire@gmail.com>2018-03-01 16:54:45 +0200
commitb786f20bbab5a59046aa78a2c6c2a11536497202 (patch)
tree0851ecdec889eb9b7ba3751cc04d4f0b474e4a9e /libbio/bwrite.c
inferno-os tree was separated from the inferno-os-android (separated from the Android driver)
Diffstat (limited to 'libbio/bwrite.c')
-rw-r--r--libbio/bwrite.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/libbio/bwrite.c b/libbio/bwrite.c
new file mode 100644
index 0000000..7661b74
--- /dev/null
+++ b/libbio/bwrite.c
@@ -0,0 +1,42 @@
+#include "lib9.h"
+#include <bio.h>
+
+long
+Bwrite(Biobuf *bp, void *ap, long count)
+{
+ long c;
+ uchar *p;
+ int i, n, oc;
+ char errbuf[ERRMAX];
+
+ p = ap;
+ c = count;
+ oc = bp->ocount;
+
+ while(c > 0) {
+ n = -oc;
+ if(n > c)
+ n = c;
+ if(n == 0) {
+ if(bp->state != Bwactive)
+ return Beof;
+ i = write(bp->fid, bp->bbuf, bp->bsize);
+ if(i != bp->bsize) {
+ errstr(errbuf, sizeof errbuf);
+ if(strstr(errbuf, "interrupt") == nil)
+ bp->state = Binactive;
+ errstr(errbuf, sizeof errbuf);
+ return Beof;
+ }
+ bp->offset += i;
+ oc = -bp->bsize;
+ continue;
+ }
+ memmove(bp->ebuf+oc, p, n);
+ oc += n;
+ c -= n;
+ p += n;
+ }
+ bp->ocount = oc;
+ return count-c;
+}