bio: remove useless Breadn() as it does the same as Bread()
Bread() always reads exactly nbytes of data if it can. only when it reaches end of file or an error it will return less. so the Breadn() function that was introduced has been removed. sorry for the confusion.
This commit is contained in:
parent
e7348f8ed2
commit
7ceff03db3
|
@ -66,7 +66,6 @@ int Bputrune(Biobufhdr*, long);
|
||||||
void* Brdline(Biobufhdr*, int);
|
void* Brdline(Biobufhdr*, int);
|
||||||
char* Brdstr(Biobufhdr*, int, int);
|
char* Brdstr(Biobufhdr*, int, int);
|
||||||
long Bread(Biobufhdr*, void*, long);
|
long Bread(Biobufhdr*, void*, long);
|
||||||
long Breadn(Biobufhdr*, void*, long);
|
|
||||||
vlong Bseek(Biobufhdr*, vlong, int);
|
vlong Bseek(Biobufhdr*, vlong, int);
|
||||||
int Bterm(Biobufhdr*);
|
int Bterm(Biobufhdr*);
|
||||||
int Bungetc(Biobufhdr*);
|
int Bungetc(Biobufhdr*);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.TH BIO 2
|
.TH BIO 2
|
||||||
.SH NAME
|
.SH NAME
|
||||||
Bopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Breadn, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal \- buffered input/output
|
Bopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal \- buffered input/output
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.ta \w'Biobuf* 'u
|
.ta \w'Biobuf* 'u
|
||||||
.B #include <u.h>
|
.B #include <u.h>
|
||||||
|
@ -70,9 +70,6 @@ int Bputrune(Biobufhdr *bp, long c)
|
||||||
long Bread(Biobufhdr *bp, void *addr, long nbytes)
|
long Bread(Biobufhdr *bp, void *addr, long nbytes)
|
||||||
.PP
|
.PP
|
||||||
.B
|
.B
|
||||||
long Breadn(Biobufhdr *bp, void *addr, long nbytes)
|
|
||||||
.PP
|
|
||||||
.B
|
|
||||||
long Bwrite(Biobufhdr *bp, void *addr, long nbytes)
|
long Bwrite(Biobufhdr *bp, void *addr, long nbytes)
|
||||||
.PP
|
.PP
|
||||||
.B
|
.B
|
||||||
|
@ -239,13 +236,6 @@ into memory starting at
|
||||||
The number of bytes read is returned on success
|
The number of bytes read is returned on success
|
||||||
and a negative value is returned if a read error occurred.
|
and a negative value is returned if a read error occurred.
|
||||||
.PP
|
.PP
|
||||||
.I Breadn
|
|
||||||
is like
|
|
||||||
.I Bread
|
|
||||||
but continues reading until
|
|
||||||
.I nbytes
|
|
||||||
have been read into the buffer.
|
|
||||||
.PP
|
|
||||||
.I Bseek
|
.I Bseek
|
||||||
applies
|
applies
|
||||||
.IR seek (2)
|
.IR seek (2)
|
||||||
|
|
|
@ -60,7 +60,7 @@ Bgetheader(Biobuf *b, Header *h)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(h, 0, sizeof(*h));
|
memset(h, 0, sizeof(*h));
|
||||||
if(Breadn(b, buf, 6) != 6)
|
if(Bread(b, buf, 6) != 6)
|
||||||
goto eof;
|
goto eof;
|
||||||
if(gets(&buf[0]) != 0)
|
if(gets(&buf[0]) != 0)
|
||||||
goto header;
|
goto header;
|
||||||
|
@ -71,7 +71,7 @@ Bgetheader(Biobuf *b, Header *h)
|
||||||
icon = mallocz(sizeof(*icon), 1);
|
icon = mallocz(sizeof(*icon), 1);
|
||||||
if(icon == nil)
|
if(icon == nil)
|
||||||
sysfatal("malloc: %r");
|
sysfatal("malloc: %r");
|
||||||
if(Breadn(b, buf, 16) != 16)
|
if(Bread(b, buf, 16) != 16)
|
||||||
goto eof;
|
goto eof;
|
||||||
icon->w = buf[0] == 0 ? 256 : buf[0];
|
icon->w = buf[0] == 0 ? 256 : buf[0];
|
||||||
icon->h = buf[1] == 0 ? 256 : buf[1];
|
icon->h = buf[1] == 0 ? 256 : buf[1];
|
||||||
|
@ -215,7 +215,7 @@ Bgeticon(Biobuf *b, Icon *icon)
|
||||||
buf = malloc(icon->len);
|
buf = malloc(icon->len);
|
||||||
if(buf == nil)
|
if(buf == nil)
|
||||||
return -1;
|
return -1;
|
||||||
if(Breadn(b, buf, icon->len) != icon->len){
|
if(Bread(b, buf, icon->len) != icon->len){
|
||||||
werrstr("unexpected EOF");
|
werrstr("unexpected EOF");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,7 +320,7 @@ load_16(Biobuf *b, long width, long height, Rgb* buf, Rgb* clut)
|
||||||
for(iy = height; iy; iy--, i += step_up)
|
for(iy = height; iy; iy--, i += step_up)
|
||||||
for(ix = 0; ix < width; ix++, i++) {
|
for(ix = 0; ix < width; ix++, i++) {
|
||||||
unsigned val;
|
unsigned val;
|
||||||
Breadn(b, c, sizeof(c));
|
Bread(b, c, sizeof(c));
|
||||||
val = (unsigned)c[0] + ((unsigned)c[1] << 8);
|
val = (unsigned)c[0] + ((unsigned)c[1] << 8);
|
||||||
|
|
||||||
buf[i].alpha = 0;
|
buf[i].alpha = 0;
|
||||||
|
@ -340,7 +340,7 @@ load_16(Biobuf *b, long width, long height, Rgb* buf, Rgb* clut)
|
||||||
} else
|
} else
|
||||||
for(iy = height; iy; iy--, i += step_up)
|
for(iy = height; iy; iy--, i += step_up)
|
||||||
for(ix = 0; ix < width; ix++, i++) {
|
for(ix = 0; ix < width; ix++, i++) {
|
||||||
Breadn(b, c, sizeof(c));
|
Bread(b, c, sizeof(c));
|
||||||
buf[i].blue = (uchar)((c[0] << 3) & 0xf8);
|
buf[i].blue = (uchar)((c[0] << 3) & 0xf8);
|
||||||
buf[i].green = (uchar)(((((unsigned)c[1] << 6) +
|
buf[i].green = (uchar)(((((unsigned)c[1] << 6) +
|
||||||
(((unsigned)c[0]) >> 2))) & 0xf8);
|
(((unsigned)c[0]) >> 2))) & 0xf8);
|
||||||
|
@ -406,7 +406,7 @@ load_32(Biobuf *b, long width, long height, Rgb* buf, Rgb* clut)
|
||||||
for(iy = height; iy; iy--, i += step_up)
|
for(iy = height; iy; iy--, i += step_up)
|
||||||
for(ix = 0; ix < width; ix++, i++) {
|
for(ix = 0; ix < width; ix++, i++) {
|
||||||
ulong val;
|
ulong val;
|
||||||
Breadn(b, c, sizeof(c));
|
Bread(b, c, sizeof(c));
|
||||||
val = (ulong)c[0] + ((ulong)c[1] << 8) +
|
val = (ulong)c[0] + ((ulong)c[1] << 8) +
|
||||||
((ulong)c[2] << 16) + ((ulong)c[1] << 24);
|
((ulong)c[2] << 16) + ((ulong)c[1] << 24);
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ load_32(Biobuf *b, long width, long height, Rgb* buf, Rgb* clut)
|
||||||
} else
|
} else
|
||||||
for(iy = height; iy; iy--, i += step_up)
|
for(iy = height; iy; iy--, i += step_up)
|
||||||
for(ix = 0; ix < width; ix++, i++) {
|
for(ix = 0; ix < width; ix++, i++) {
|
||||||
Breadn(b, c, nelem(c));
|
Bread(b, c, nelem(c));
|
||||||
buf[i].blue = c[0];
|
buf[i].blue = c[0];
|
||||||
buf[i].green = c[1];
|
buf[i].green = c[1];
|
||||||
buf[i].red = c[2];
|
buf[i].red = c[2];
|
||||||
|
|
|
@ -224,7 +224,7 @@ static
|
||||||
void
|
void
|
||||||
readheader(Header *h)
|
readheader(Header *h)
|
||||||
{
|
{
|
||||||
if(Breadn(h->fd, h->buf, 13) != 13)
|
if(Bread(h->fd, h->buf, 13) != 13)
|
||||||
giferror(h, "ReadGIF: can't read header: %r");
|
giferror(h, "ReadGIF: can't read header: %r");
|
||||||
memmove(h->vers, h->buf, 6);
|
memmove(h->vers, h->buf, 6);
|
||||||
if(strcmp(h->vers, "GIF87a")!=0 && strcmp(h->vers, "GIF89a")!=0)
|
if(strcmp(h->vers, "GIF87a")!=0 && strcmp(h->vers, "GIF89a")!=0)
|
||||||
|
@ -249,7 +249,7 @@ readcmap(Header *h, int size)
|
||||||
if(size > 8)
|
if(size > 8)
|
||||||
giferror(h, "ReadGIF: can't handles %d bits per pixel", size);
|
giferror(h, "ReadGIF: can't handles %d bits per pixel", size);
|
||||||
size = 3*(1<<size);
|
size = 3*(1<<size);
|
||||||
if(Breadn(h->fd, h->buf, size) != size)
|
if(Bread(h->fd, h->buf, size) != size)
|
||||||
giferror(h, "ReadGIF: short read on color map");
|
giferror(h, "ReadGIF: short read on color map");
|
||||||
map = malloc(size);
|
map = malloc(size);
|
||||||
if(map == nil)
|
if(map == nil)
|
||||||
|
@ -265,7 +265,7 @@ readone(Header *h)
|
||||||
Rawimage *i;
|
Rawimage *i;
|
||||||
int left, top, width, height;
|
int left, top, width, height;
|
||||||
|
|
||||||
if(Breadn(h->fd, h->buf, 9) != 9)
|
if(Bread(h->fd, h->buf, 9) != 9)
|
||||||
giferror(h, "ReadGIF: can't read image descriptor: %r");
|
giferror(h, "ReadGIF: can't read image descriptor: %r");
|
||||||
i = malloc(sizeof(Rawimage));
|
i = malloc(sizeof(Rawimage));
|
||||||
if(i == nil)
|
if(i == nil)
|
||||||
|
@ -297,7 +297,7 @@ readdata(Header *h, uchar *data)
|
||||||
giferror(h, "ReadGIF: can't read data: %r");
|
giferror(h, "ReadGIF: can't read data: %r");
|
||||||
if(nbytes == 0)
|
if(nbytes == 0)
|
||||||
return 0;
|
return 0;
|
||||||
n = Breadn(h->fd, data, nbytes);
|
n = Bread(h->fd, data, nbytes);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
giferror(h, "ReadGIF: can't read data: %r");
|
giferror(h, "ReadGIF: can't read data: %r");
|
||||||
if(n != nbytes)
|
if(n != nbytes)
|
||||||
|
@ -309,7 +309,7 @@ static
|
||||||
void
|
void
|
||||||
graphiccontrol(Header *h)
|
graphiccontrol(Header *h)
|
||||||
{
|
{
|
||||||
if(Breadn(h->fd, h->buf, 5+1) != 5+1)
|
if(Bread(h->fd, h->buf, 5+1) != 5+1)
|
||||||
giferror(h, readerr);
|
giferror(h, readerr);
|
||||||
h->flags = h->buf[1];
|
h->flags = h->buf[1];
|
||||||
h->delay = h->buf[2]+(h->buf[3]<<8);
|
h->delay = h->buf[2]+(h->buf[3]<<8);
|
||||||
|
@ -350,7 +350,7 @@ skipextension(Header *h)
|
||||||
default:
|
default:
|
||||||
giferror(h, "ReadGIF: unknown extension");
|
giferror(h, "ReadGIF: unknown extension");
|
||||||
}
|
}
|
||||||
if(hsize>0 && Breadn(h->fd, h->buf, hsize) != hsize)
|
if(hsize>0 && Bread(h->fd, h->buf, hsize) != hsize)
|
||||||
giferror(h, extreaderr);
|
giferror(h, extreaderr);
|
||||||
if(!hasdata){
|
if(!hasdata){
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -450,7 +450,7 @@ readsegment(Header *h, int *markerp)
|
||||||
*markerp = m;
|
*markerp = m;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(Breadn(h->fd, tmp, 2) != 2)
|
if(Bread(h->fd, tmp, 2) != 2)
|
||||||
Readerr:
|
Readerr:
|
||||||
jpgerror(h, readerr);
|
jpgerror(h, readerr);
|
||||||
n = int2(tmp, 0);
|
n = int2(tmp, 0);
|
||||||
|
@ -464,7 +464,7 @@ readsegment(Header *h, int *markerp)
|
||||||
h->nbuf = n;
|
h->nbuf = n;
|
||||||
}
|
}
|
||||||
/* accept short reads to cope with some real-world jpegs */
|
/* accept short reads to cope with some real-world jpegs */
|
||||||
if(Breadn(h->fd, h->buf, n) < 0)
|
if(Bread(h->fd, h->buf, n) < 0)
|
||||||
goto Readerr;
|
goto Readerr;
|
||||||
*markerp = m;
|
*markerp = m;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
@ -100,19 +100,19 @@ getchunk(Biobuf *b, char *type, uchar *d, int m)
|
||||||
ulong crc = 0, crc2;
|
ulong crc = 0, crc2;
|
||||||
int n, nr;
|
int n, nr;
|
||||||
|
|
||||||
if(Breadn(b, buf, 8) != 8)
|
if(Bread(b, buf, 8) != 8)
|
||||||
return -1;
|
return -1;
|
||||||
n = get4(buf);
|
n = get4(buf);
|
||||||
memmove(type, buf+4, 4);
|
memmove(type, buf+4, 4);
|
||||||
type[4] = 0;
|
type[4] = 0;
|
||||||
if(n > m)
|
if(n > m)
|
||||||
sysfatal("getchunk needed %d, had %d", n, m);
|
sysfatal("getchunk needed %d, had %d", n, m);
|
||||||
nr = Breadn(b, d, n);
|
nr = Bread(b, d, n);
|
||||||
if(nr != n)
|
if(nr != n)
|
||||||
sysfatal("getchunk read %d, expected %d", nr, n);
|
sysfatal("getchunk read %d, expected %d", nr, n);
|
||||||
crc = blockcrc(crctab, crc, type, 4);
|
crc = blockcrc(crctab, crc, type, 4);
|
||||||
crc = blockcrc(crctab, crc, d, n);
|
crc = blockcrc(crctab, crc, d, n);
|
||||||
if(Breadn(b, buf, 4) != 4)
|
if(Bread(b, buf, 4) != 4)
|
||||||
sysfatal("getchunk tlr failed");
|
sysfatal("getchunk tlr failed");
|
||||||
crc2 = get4(buf);
|
crc2 = get4(buf);
|
||||||
if(crc != crc2)
|
if(crc != crc2)
|
||||||
|
@ -388,7 +388,7 @@ readslave(Biobuf *b)
|
||||||
ZlibW zw;
|
ZlibW zw;
|
||||||
|
|
||||||
buf = pngmalloc(IDATSIZE, 0);
|
buf = pngmalloc(IDATSIZE, 0);
|
||||||
Breadn(b, buf, sizeof PNGmagic);
|
Bread(b, buf, sizeof PNGmagic);
|
||||||
if(memcmp(PNGmagic, buf, sizeof PNGmagic) != 0)
|
if(memcmp(PNGmagic, buf, sizeof PNGmagic) != 0)
|
||||||
sysfatal("bad PNGmagic");
|
sysfatal("bad PNGmagic");
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ rdhdr(Biobuf *bp)
|
||||||
free(h);
|
free(h);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if(Breadn(bp, h->cmap, n) != n){
|
if(Bread(bp, h->cmap, n) != n){
|
||||||
free(h);
|
free(h);
|
||||||
free(h->cmap);
|
free(h->cmap);
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -124,7 +124,7 @@ rdhdr(Biobuf *bp)
|
||||||
static int
|
static int
|
||||||
luma(Biobuf *bp, uchar *l, int num)
|
luma(Biobuf *bp, uchar *l, int num)
|
||||||
{
|
{
|
||||||
return Breadn(bp, l, num);
|
return Bread(bp, l, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -164,7 +164,7 @@ rgba(Biobuf *bp, int bpp, uchar *r, uchar *g, uchar *b, int num)
|
||||||
switch(bpp){
|
switch(bpp){
|
||||||
case 16:
|
case 16:
|
||||||
for(i = 0; i < num; i++){
|
for(i = 0; i < num; i++){
|
||||||
if(Breadn(bp, buf, 2) != 2)
|
if(Bread(bp, buf, 2) != 2)
|
||||||
break;
|
break;
|
||||||
x = buf[0];
|
x = buf[0];
|
||||||
y = buf[1];
|
y = buf[1];
|
||||||
|
@ -175,7 +175,7 @@ rgba(Biobuf *bp, int bpp, uchar *r, uchar *g, uchar *b, int num)
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
for(i = 0; i < num; i++){
|
for(i = 0; i < num; i++){
|
||||||
if(Breadn(bp, buf, 3) != 3)
|
if(Bread(bp, buf, 3) != 3)
|
||||||
break;
|
break;
|
||||||
*b++ = buf[0];
|
*b++ = buf[0];
|
||||||
*g++ = buf[1];
|
*g++ = buf[1];
|
||||||
|
@ -184,7 +184,7 @@ rgba(Biobuf *bp, int bpp, uchar *r, uchar *g, uchar *b, int num)
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
for(i = 0; i < num; i++){
|
for(i = 0; i < num; i++){
|
||||||
if(Breadn(bp, buf, 4) != 4)
|
if(Bread(bp, buf, 4) != 4)
|
||||||
break;
|
break;
|
||||||
*b++ = buf[0];
|
*b++ = buf[0];
|
||||||
*g++ = buf[1];
|
*g++ = buf[1];
|
||||||
|
|
|
@ -120,7 +120,7 @@ BreadV210(Biobuf *bp, int colourspace)
|
||||||
goto Error;
|
goto Error;
|
||||||
|
|
||||||
for(l = 0; l < lines; l++){
|
for(l = 0; l < lines; l++){
|
||||||
if(Breadn(bp, buf, chunk) == -1)
|
if(Bread(bp, buf, chunk) == -1)
|
||||||
goto Error;
|
goto Error;
|
||||||
|
|
||||||
rd = 0;
|
rd = 0;
|
||||||
|
|
|
@ -126,7 +126,7 @@ Breadyuv(Biobuf *bp, int colourspace)
|
||||||
goto Error;
|
goto Error;
|
||||||
|
|
||||||
for (l = 0; l < lines; l++) {
|
for (l = 0; l < lines; l++) {
|
||||||
if (Breadn(bp, buf, pixels *2) == -1)
|
if (Bread(bp, buf, pixels *2) == -1)
|
||||||
goto Error;
|
goto Error;
|
||||||
|
|
||||||
base = l*pixels*2;
|
base = l*pixels*2;
|
||||||
|
@ -137,7 +137,7 @@ Breadyuv(Biobuf *bp, int colourspace)
|
||||||
|
|
||||||
if (bits == 10)
|
if (bits == 10)
|
||||||
for (l = 0; l < lines; l++) {
|
for (l = 0; l < lines; l++) {
|
||||||
if (Breadn(bp, buf, pixels / 2) == -1)
|
if (Bread(bp, buf, pixels / 2) == -1)
|
||||||
goto Error;
|
goto Error;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ vncrdcorect(Vnc *v)
|
||||||
void
|
void
|
||||||
vncrdbytes(Vnc *v, void *a, int n)
|
vncrdbytes(Vnc *v, void *a, int n)
|
||||||
{
|
{
|
||||||
if(Breadn(&v->in, a, n) != n){
|
if(Bread(&v->in, a, n) != n){
|
||||||
if(verbose > 1)
|
if(verbose > 1)
|
||||||
fprint(2, "hungup while reading\n");
|
fprint(2, "hungup while reading\n");
|
||||||
vnchungup(v);
|
vnchungup(v);
|
||||||
|
|
Loading…
Reference in a new issue