2 * UCW Library -- A simple growing buffer
4 * (c) 2004, Robert Spalek <robert@ucw.cz>
6 * Define the following macros:
8 * GBUF_TYPE data type of records stored in the buffer
9 * GBUF_PREFIX(x) add a name prefix to all global symbols
11 * This software may be freely distributed and used according to the terms
12 * of the GNU Lesser General Public License.
17 #define BUF_T GBUF_PREFIX(t)
27 GBUF_PREFIX(init)(BUF_T *b)
34 GBUF_PREFIX(done)(BUF_T *b)
43 GBUF_PREFIX(realloc)(BUF_T *b, uns len)
46 b->ptr = xrealloc(b->ptr, len * sizeof(GBUF_TYPE));
50 GBUF_PREFIX(grow)(BUF_T *b, uns len)
52 if (likely(len <= b->len))
54 if (len < 2*b->len) // to ensure logarithmic cost
56 GBUF_PREFIX(realloc)(b, len);