tcheck against plan 9 - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 4dd07e012c124921328df5d91c272c63e015bdd5
parent 727facb60539f522635f0d8978435ce4680fecd6
Author: rsc 
Date:   Tue, 28 Dec 2004 19:25:16 +0000

check against plan 9

Diffstat:
  M src/libbio/bgetc.c                  |       1 +
  M src/libbio/binit.c                  |       6 +++---
  M src/libbio/bputc.c                  |      29 ++++++++++-------------------
  M src/libbio/lib9.std.h               |       5 +++++

4 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/src/libbio/bgetc.c b/src/libbio/bgetc.c
t@@ -26,6 +26,7 @@ loop:
         i = read(bp->fid, bp->bbuf, bp->bsize);
         bp->gbuf = bp->bbuf;
         if(i <= 0) {
+                bp->state = Bracteof;
                 if(i < 0)
                         bp->state = Binactive;
                 return Beof;
diff --git a/src/libbio/binit.c b/src/libbio/binit.c
t@@ -61,7 +61,7 @@ Binits(Biobuf *bp, int f, int mode, unsigned char *p, int size)
         p += Bungetsize;        /* make room for Bungets */
         size -= Bungetsize;
 
-        switch(mode) {
+        switch(mode&~(OCEXEC|ORCLOSE|OTRUNC)) {
         default:
                 fprint(2, "Bopen: unknown mode %d\n", mode);
                 return Beof;
t@@ -86,7 +86,7 @@ Binits(Biobuf *bp, int f, int mode, unsigned char *p, int size)
         bp->flag = 0;
         bp->rdline = 0;
         bp->offset = 0;
-/*        bp->runesize = 0; */
+        bp->runesize = 0;
         return 0;
 }
 
t@@ -116,7 +116,7 @@ Bopen(char *name, int mode)
         Biobuf *bp;
         int f;
 
-        switch(mode) {
+        switch(mode&~(OCEXEC|ORCLOSE|OTRUNC)) {
         default:
                 fprint(2, "Bopen: unknown mode %d\n", mode);
                 return 0;
diff --git a/src/libbio/bputc.c b/src/libbio/bputc.c
t@@ -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;
 }
diff --git a/src/libbio/lib9.std.h b/src/libbio/lib9.std.h
t@@ -9,6 +9,11 @@
 #define OREAD                O_RDONLY
 #define OWRITE        O_WRONLY
 
+#define        OCEXEC 0
+#define        ORCLOSE        0
+#define        OTRUNC        0
+
+
 #define nil ((void*)0)
 
 typedef long long vlong;