aboutsummaryrefslogtreecommitdiff
path: root/src/libbio/bputc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libbio/bputc.c')
-rw-r--r--src/libbio/bputc.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libbio/bputc.c b/src/libbio/bputc.c
new file mode 100644
index 00000000..5f0fba59
--- /dev/null
+++ b/src/libbio/bputc.c
@@ -0,0 +1,29 @@
+#include "lib9.h"
+#include <bio.h>
+
+int
+Bputc(Biobuf *bp, int c)
+{
+ int i, j;
+
+loop:
+ i = bp->ocount;
+ j = i+1;
+ if(i != 0) {
+ bp->ocount = j;
+ bp->ebuf[i] = c;
+ return 0;
+ }
+ 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;
+}