Lines Matching defs:buf
33 abuf_init(struct abuf *buf, unsigned int len)
35 buf->data = xmalloc(len);
36 buf->len = len;
37 buf->used = 0;
38 buf->start = 0;
42 abuf_done(struct abuf *buf)
45 if (buf->used > 0)
46 logx(3, "deleting non-empty buffer, used = %d", buf->used);
48 xfree(buf->data);
49 buf->data = (void *)0xdeadbeef;
56 abuf_rgetblk(struct abuf *buf, int *rsize)
60 count = buf->len - buf->start;
61 if (count > buf->used)
62 count = buf->used;
64 return buf->data + buf->start;
71 abuf_rdiscard(struct abuf *buf, int count)
74 if (count < 0 || count > buf->used) {
79 buf->used -= count;
80 buf->start += count;
81 if (buf->start >= buf->len)
82 buf->start -= buf->len;
89 abuf_wcommit(struct abuf *buf, int count)
92 if (count < 0 || count > (buf->len - buf->used)) {
97 buf->used += count;
104 abuf_wgetblk(struct abuf *buf, int *rsize)
108 end = buf->start + buf->used;
109 if (end >= buf->len)
110 end -= buf->len;
111 avail = buf->len - buf->used;
112 count = buf->len - end;
116 return buf->data + end;