1 b2cfc4e2 2003-09-30 devnull #include "lib9.h"
2 b2cfc4e2 2003-09-30 devnull #include <bio.h>
5 b2cfc4e2 2003-09-30 devnull Bread(Biobuf *bp, void *ap, long count)
8 b2cfc4e2 2003-09-30 devnull unsigned char *p;
9 b2cfc4e2 2003-09-30 devnull int i, n, ic;
12 b2cfc4e2 2003-09-30 devnull c = count;
13 b2cfc4e2 2003-09-30 devnull ic = bp->icount;
15 b2cfc4e2 2003-09-30 devnull while(c > 0) {
17 b2cfc4e2 2003-09-30 devnull if(n > c)
19 b2cfc4e2 2003-09-30 devnull if(n == 0) {
20 b2cfc4e2 2003-09-30 devnull if(bp->state != Bractive)
22 b2cfc4e2 2003-09-30 devnull i = read(bp->fid, bp->bbuf, bp->bsize);
23 b2cfc4e2 2003-09-30 devnull if(i <= 0) {
24 b2cfc4e2 2003-09-30 devnull bp->state = Bracteof;
25 b2cfc4e2 2003-09-30 devnull if(i < 0)
26 b2cfc4e2 2003-09-30 devnull bp->state = Binactive;
29 b2cfc4e2 2003-09-30 devnull bp->gbuf = bp->bbuf;
30 b2cfc4e2 2003-09-30 devnull bp->offset += i;
31 b2cfc4e2 2003-09-30 devnull if(i < bp->bsize) {
32 b2cfc4e2 2003-09-30 devnull memmove(bp->ebuf-i, bp->bbuf, i);
33 b2cfc4e2 2003-09-30 devnull bp->gbuf = bp->ebuf-i;
36 b2cfc4e2 2003-09-30 devnull continue;
38 b2cfc4e2 2003-09-30 devnull memmove(p, bp->ebuf+ic, n);
43 b2cfc4e2 2003-09-30 devnull bp->icount = ic;
44 b2cfc4e2 2003-09-30 devnull return count-c;