2 * Buffer handling functions
4 * Copyright (C) 2003, Olaf Kirch <okir@suse.de>
13 #include <openct/buffer.h>
16 ct_buf_init(ct_buf_t *bp, void *mem, size_t len)
18 memset(bp, 0, sizeof(*bp));
19 bp->base = (unsigned char *) mem;
24 ct_buf_set(ct_buf_t *bp, void *mem, size_t len)
26 ct_buf_init(bp, mem, len);
31 ct_buf_get(ct_buf_t *bp, void *mem, size_t len)
33 if (len > bp->tail - bp->head)
36 memcpy(mem, bp->base + bp->head, len);
42 ct_buf_put(ct_buf_t *bp, const void *mem, size_t len)
44 if (len > bp->size - bp->tail) {
49 memcpy(bp->base + bp->tail, mem, len);
55 ct_buf_putc(ct_buf_t *bp, int byte)
57 unsigned char c = byte;
59 return ct_buf_put(bp, &c, 1);
63 ct_buf_avail(ct_buf_t *bp)
65 return bp->tail - bp->head;
69 ct_buf_head(ct_buf_t *bp)
71 return bp->base + bp->head;