| 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(-)
--- |
| 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; |
| 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; |
| 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;
} |