|
|
1.1 root 1: # include <useful.h>
2: # include <pipes.h>
3: # include <sccs.h>
4:
5: SCCSID(@(#)IIpb_get.c 7.1 2/5/81)
6:
7:
8: /*
9: ** IIPB_GET -- buffered get from pipe
10: **
11: ** This routine just gets a record from the pipe block, reading
12: ** if necessary. It tries to do things in big chunks to keep
13: ** the overhead down.
14: **
15: ** Parameters:
16: ** ppb -- a pointer to the pipe block to unbuffer.
17: ** dp -- a pointer to the data area.
18: ** len -- the number of bytes to read.
19: **
20: ** Returns:
21: ** The number of bytes actually read.
22: ** Zero on end of file.
23: **
24: ** Side Effects:
25: ** none.
26: **
27: ** Trace Flags:
28: ** 18.1 - 18.7
29: */
30:
31: IIpb_get(ppb, dp, len)
32: register pb_t *ppb;
33: char *dp;
34: register int len;
35: {
36: int rct;
37: register int i;
38:
39: rct = 0;
40:
41: /*
42: ** Top Loop.
43: ** As long as we still want more, keep buffering out.
44: */
45:
46: while (len > 0)
47: {
48: /* if we have no data, read another block */
49: while (ppb->pb_nleft <= 0)
50: {
51: if (bitset(PB_EOF, ppb->pb_stat))
52: return (rct);
53: IIpb_read(ppb);
54: }
55:
56: /*
57: ** Compute the length to move.
58: ** This is the min of the amount we want and the
59: ** amount we have available to us in the buffer.
60: */
61:
62: i = min(ppb->pb_nleft, len);
63: IIbmove(ppb->pb_xptr, dp, i);
64: ppb->pb_xptr += i;
65: ppb->pb_nleft -= i;
66: dp += i;
67: len -= i;
68: rct += i;
69: }
70:
71: return (rct);
72: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.