diff th_util.h @ 109:fedad0ed894f

Remove th_growbuf, move to th_util.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Jun 2014 20:42:06 +0300
parents a8f732601fdc
children cddfc43a4e45
line wrap: on
line diff
--- a/th_util.h	Sat Jun 21 20:22:49 2014 +0300
+++ b/th_util.h	Sat Jun 21 20:42:06 2014 +0300
@@ -187,6 +187,43 @@
 void         th_ringbuf_add(qringbuf_t *buf, void *ptr);
 
 
+/* Growing buffers
+ */
+#define TH_BUFGROW       (32)
+
+
+typedef struct
+{
+    BOOL allocated;
+    uint8_t *data;
+    size_t size, len, mingrow;
+} th_growbuf_t;
+
+
+/* Simple growing string buffer
+ */
+BOOL    th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, const size_t grow);
+BOOL    th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const char ch);
+BOOL    th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str);
+
+
+/* Growing byte buffer
+ */
+void    th_growbuf_init(th_growbuf_t *buf, const size_t mingrow);
+th_growbuf_t *th_growbuf_new(const size_t mingrow);
+void    th_growbuf_free(th_growbuf_t *buf);
+
+
+BOOL    th_growbuf_grow(th_growbuf_t *buf, const size_t grow);
+BOOL    th_growbuf_puts(th_growbuf_t *buf, const char *str, BOOL eos);
+BOOL    th_growbuf_putch(th_growbuf_t *buf, const char ch);
+BOOL    th_growbuf_put_u8(th_growbuf_t *buf, const uint8_t val);
+BOOL    th_growbuf_put_u16_be(th_growbuf_t *buf, const uint16_t val);
+BOOL    th_growbuf_put_u16_le(th_growbuf_t *buf, const uint16_t val);
+BOOL    th_growbuf_put_u32_be(th_growbuf_t *buf, const uint32_t val);
+BOOL    th_growbuf_put_u32_le(th_growbuf_t *buf, const uint32_t val);
+
+
 #ifdef __cplusplus
 }
 #endif