Lines Matching defs:buf
29 abuf_init(struct abuf *buf, unsigned int len)
31 buf->data = xmalloc(len);
32 buf->len = len;
33 buf->used = 0;
34 buf->start = 0;
38 abuf_done(struct abuf *buf)
41 if (buf->used > 0)
42 logx(3, "deleting non-empty buffer, used = %d", buf->used);
44 xfree(buf->data);
45 buf->data = (void *)0xdeadbeef;
52 abuf_rgetblk(struct abuf *buf, int *rsize)
56 count = buf->len - buf->start;
57 if (count > buf->used)
58 count = buf->used;
60 return buf->data + buf->start;
67 abuf_rdiscard(struct abuf *buf, int count)
70 if (count < 0 || count > buf->used) {
75 buf->used -= count;
76 buf->start += count;
77 if (buf->start >= buf->len)
78 buf->start -= buf->len;
85 abuf_wcommit(struct abuf *buf, int count)
88 if (count < 0 || count > (buf->len - buf->used)) {
93 buf->used += count;
100 abuf_wgetblk(struct abuf *buf, int *rsize)
104 end = buf->start + buf->used;
105 if (end >= buf->len)
106 end -= buf->len;
107 avail = buf->len - buf->used;
108 count = buf->len - end;
112 return buf->data + end;