summaryrefslogtreecommitdiff
path: root/sys/src/libbio/breadn.c
blob: fa335873f337d650cfc743acd093e9662f5b0b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
}