Lines Matching defs:xbuf
2 #include "xbuf.h"
7 public void xbuf_init(struct xbuffer *xbuf)
9 xbuf_init_size(xbuf, 16);
12 public void xbuf_init_size(struct xbuffer *xbuf, size_t init_size)
14 xbuf->data = NULL;
15 xbuf->size = xbuf->end = 0;
16 xbuf->init_size = init_size;
20 * Free buffer space in an xbuf.
22 public void xbuf_deinit(struct xbuffer *xbuf)
24 if (xbuf->data != NULL)
25 free(xbuf->data);
26 xbuf_init(xbuf);
30 * Set xbuf to empty.
32 public void xbuf_reset(struct xbuffer *xbuf)
34 xbuf->end = 0;
38 * Add a byte to an xbuf.
40 public void xbuf_add_byte(struct xbuffer *xbuf, unsigned char b)
42 if (xbuf->end >= xbuf->size)
45 if (ckd_add(&xbuf->size, xbuf->size, xbuf->size ? xbuf->size : xbuf->init_size))
47 data = (unsigned char *) ecalloc(xbuf->size, sizeof(unsigned char));
48 if (xbuf->data != NULL)
50 memcpy(data, xbuf->data, xbuf->end);
51 free(xbuf->data);
53 xbuf->data = data;
55 xbuf->data[xbuf->end++] = b;
59 * Add a char to an xbuf.
61 public void xbuf_add_char(struct xbuffer *xbuf, char c)
63 xbuf_add_byte(xbuf, (unsigned char) c);
67 * Add arbitrary data to an xbuf.
69 public void xbuf_add_data(struct xbuffer *xbuf, constant unsigned char *data, size_t len)
73 xbuf_add_byte(xbuf, data[i]);
77 * Remove the last byte from an xbuf.
87 * Set an xbuf to the contents of another xbuf.
96 * Return xbuf data as a char*.
98 public constant char * xbuf_char_data(constant struct xbuffer *xbuf)
100 return (constant char *)(xbuf->data);