* Miscellanious buffer management routines
* The University of British Columbia
* Laboratory for Computational Vision
* return a buffer that contains room
* for 'size' bytes of data.
if ((bp
= (struct buf
*)malloc (size
+ sizeof(char *)*4)) == 0)
bp
->b_next
= bp
->b_prev
= bp
;
bp
->b_top
= bp
->b_bot
= bp
->b_data
;
* Initialize a buffer queue by
* freeing all buffers on the queue
* and resetting the queue to its
register struct bufhd
*qp
;
dequeue (bp
= qp
->b_next
, qp
);
qp
->b_prev
= qp
->b_next
= (struct buf
*)qp
;
* Allocate a buffer and try to read 'size' bytes from 'fd'.
* Return zero on error; otherwise return a pointer to the buffer.
if ((n
= read (fd
, bp
->b_bot
, size
)) <= 0) {
NimTrace (who
, bp
->b_bot
, n
);
* Try to flush the queue of buffers headed by 'qp'
* by writing to 'fd'. Returns non-zero on error.
register struct bufhd
*qp
;
if ((cc
= write (fd
, bp
->b_bot
, SIZE (bp
))) < 0)
NimTrace (who
, bp
->b_bot
, cc
);
* Copy string 's' to buffer 'bp'.
* Copy the contents of buffer 'from' to 'to'.
register int l
= SIZE (from
);
bcopy (from
->b_bot
, to
->b_top
, l
);
* place buffer 'bp' on the end of
* the queue headed by 'qp'.
register struct bufhd
*qp
;
bp
->b_next
= (struct buf
*)qp
;
qp
->b_count
+= SIZE (bp
);
* remove buffer 'bp' from the
register struct bufhd
*qp
;
bp
->b_prev
->b_next
= bp
->b_next
;
bp
->b_next
->b_prev
= bp
->b_prev
;
qp
->b_count
-= SIZE (bp
);