libbio: add Breadn
This commit is contained in:
parent
7e744bda2b
commit
c0c9a9927f
4 changed files with 39 additions and 1 deletions
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…
Add table
Add a link
Reference in a new issue