Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/libbio/bread.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include	<u.h>
2
#include	<libc.h>
3
#include	<bio.h>
4
 
5
long
6
Bread(Biobufhdr *bp, void *ap, long count)
7
{
8
	long c;
9
	uchar *p;
10
	int i, n, ic;
11
 
12
	p = ap;
13
	c = count;
14
	ic = bp->icount;
15
 
16
	while(c > 0) {
17
		n = -ic;
18
		if(n > c)
19
			n = c;
20
		if(n == 0) {
21
			if(bp->state != Bractive)
22
				break;
23
			i = read(bp->fid, bp->bbuf, bp->bsize);
24
			if(i <= 0) {
25
				bp->state = Bracteof;
26
				if(i < 0)
27
					bp->state = Binactive;
28
				break;
29
			}
30
			bp->gbuf = bp->bbuf;
31
			bp->offset += i;
32
			if(i < bp->bsize) {
33
				memmove(bp->ebuf-i, bp->bbuf, i);
34
				bp->gbuf = bp->ebuf-i;
35
			}
36
			ic = -i;
37
			continue;
38
		}
39
		memmove(p, bp->ebuf+ic, n);
40
		c -= n;
41
		ic += n;
42
		p += n;
43
	}
44
	bp->icount = ic;
45
	if(count == c && bp->state == Binactive)
46
		return -1;
47
	return count-c;
48
}