added Blethal to libbio

This commit is contained in:
aiju 2011-07-12 18:39:40 +02:00
parent 9f31fa9d8e
commit 5851650367
10 changed files with 20 additions and 3 deletions

View file

@ -32,6 +32,7 @@ struct Biobufhdr
uchar* bbuf; /* pointer to beginning of buffer */
uchar* ebuf; /* pointer to end of buffer */
uchar* gbuf; /* pointer to good data in buf */
void (*errorf)(char *); /* called on error if not nil */
};
struct Biobuf
@ -70,5 +71,7 @@ int Bterm(Biobufhdr*);
int Bungetc(Biobufhdr*);
int Bungetrune(Biobufhdr*);
long Bwrite(Biobufhdr*, void*, long);
void Blethal(Biobufhdr*, void(*)(char*));
void Berror(Biobufhdr*, char*, ...);
#pragma varargck argpos Bprint 2

View file

@ -199,6 +199,7 @@ outcode(void)
return;
}
Binit(&b, f, OWRITE);
Blethal(&b, nil);
Bseek(&b, 0L, 2);
outhist(&b);
for(sym=0; sym<NSYM; sym++) {

View file

@ -20,6 +20,7 @@ Bflush(Biobufhdr *bp)
}
bp->state = Binactive;
bp->ocount = 0;
Berror(bp, "write error: %r");
break;
case Bracteof:

View file

@ -28,8 +28,10 @@ loop:
bp->gbuf = bp->bbuf;
if(i <= 0) {
bp->state = Bracteof;
if(i < 0)
if(i < 0) {
bp->state = Binactive;
Berror(bp, "read error: %r");
}
return Beof;
}
if(i < bp->bsize) {

View file

@ -83,6 +83,7 @@ Binits(Biobufhdr *bp, int f, int mode, uchar *p, int size)
bp->rdline = 0;
bp->offset = 0;
bp->runesize = 0;
bp->errorf = nil;
return 0;
}

View file

@ -47,6 +47,8 @@ Brdline(Biobufhdr *bp, int delim)
ip = (char*)bp->bbuf + i;
while(i < bp->bsize) {
j = read(bp->fid, ip, bp->bsize-i);
if(j < 0)
Berror(bp, "read error: %r");
if(j <= 0) {
/*
* end of file with no delim

View file

@ -67,6 +67,8 @@ Brdstr(Biobufhdr *bp, int delim, int nulldelim)
ip = (char*)bp->bbuf + i;
while(i < bp->bsize) {
j = read(bp->fid, ip, bp->bsize-i);
if(j < 0)
Berror(bp, "read error: %r");
if(j <= 0 && i == 0)
return p;
if(j <= 0 && i > 0){

View file

@ -23,8 +23,10 @@ Bread(Biobufhdr *bp, void *ap, long count)
i = read(bp->fid, bp->bbuf, bp->bsize);
if(i <= 0) {
bp->state = Bracteof;
if(i < 0)
if(i < 0) {
Berror(bp, "read error: %r");
bp->state = Binactive;
}
break;
}
bp->gbuf = bp->bbuf;

View file

@ -24,8 +24,10 @@ Bwrite(Biobufhdr *bp, void *ap, long count)
i = write(bp->fid, bp->bbuf, bp->bsize);
if(i != bp->bsize) {
errstr(errbuf, sizeof errbuf);
if(strstr(errbuf, "interrupt") == nil)
if(strstr(errbuf, "interrupt") == nil) {
bp->state = Binactive;
Berror(bp, "write error: %s", errbuf);
}
errstr(errbuf, sizeof errbuf);
return Beof;
}

View file

@ -9,6 +9,7 @@ OFILES=\
bgetc.$O\
bgetd.$O\
binit.$O\
blethal.$O\
boffset.$O\
bprint.$O\
bputrune.$O\