libbio: add Breadn
This commit is contained in:
parent
7e744bda2b
commit
c0c9a9927f
4 changed files with 39 additions and 1 deletions
|
@ -66,6 +66,7 @@ int Bputrune(Biobufhdr*, long);
|
|||
void* Brdline(Biobufhdr*, int);
|
||||
char* Brdstr(Biobufhdr*, int, int);
|
||||
long Bread(Biobufhdr*, void*, long);
|
||||
long Breadn(Biobufhdr*, void*, long);
|
||||
vlong Bseek(Biobufhdr*, vlong, int);
|
||||
int Bterm(Biobufhdr*);
|
||||
int Bungetc(Biobufhdr*);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.TH BIO 2
|
||||
.SH NAME
|
||||
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
|
||||
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
|
||||
.SH SYNOPSIS
|
||||
.ta \w'Biobuf* 'u
|
||||
.B #include <u.h>
|
||||
|
@ -70,6 +70,9 @@ int Bputrune(Biobufhdr *bp, long c)
|
|||
long Bread(Biobufhdr *bp, void *addr, long nbytes)
|
||||
.PP
|
||||
.B
|
||||
long Breadn(Biobufhdr *bp, void *addr, long nbytes)
|
||||
.PP
|
||||
.B
|
||||
long Bwrite(Biobufhdr *bp, void *addr, long nbytes)
|
||||
.PP
|
||||
.B
|
||||
|
@ -236,6 +239,13 @@ into memory starting at
|
|||
The number of bytes read is returned on success
|
||||
and a negative value is returned if a read error occurred.
|
||||
.PP
|
||||
.I Breadn
|
||||
is like
|
||||
.I Bread
|
||||
but continues reading until
|
||||
.I nbytes
|
||||
have been read into the buffer.
|
||||
.PP
|
||||
.I Bseek
|
||||
applies
|
||||
.IR seek (2)
|
||||
|
|
26
sys/src/libbio/breadn.c
Normal file
26
sys/src/libbio/breadn.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <bio.h>
|
||||
|
||||
long
|
||||
Breadn(Biobufhdr *bp, void *data, long len)
|
||||
{
|
||||
char *e, *p;
|
||||
int n;
|
||||
|
||||
p = data;
|
||||
e = p + len;
|
||||
if(e < p){
|
||||
Berror(bp, "invalid read length");
|
||||
return -1;
|
||||
}
|
||||
while(p < e){
|
||||
if((n = Bread(bp, p, e - p)) <= 0){
|
||||
if(n < 0 && p == data)
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
p += n;
|
||||
}
|
||||
return p - (char*)data;
|
||||
}
|
|
@ -17,6 +17,7 @@ OFILES=\
|
|||
brdline.$O\
|
||||
brdstr.$O\
|
||||
bread.$O\
|
||||
breadn.$O\
|
||||
bseek.$O\
|
||||
bwrite.$O\
|
||||
bvprint.$O\
|
||||
|
|
Loading…
Reference in a new issue