view th_growbuf.h @ 108:87f1caa659d4

Improved API.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Jun 2014 20:22:49 +0300
parents 4bba5be9d3bf
children
line wrap: on
line source

/*
 * Growing buffer implementations
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2002-2014 Tecnic Software productions (TNSP)
 *
 * Please read file 'COPYING' for information on license and distribution.
 */
#ifndef TH_GROWBUF_H
#define TH_GROWBUF_H

#include "th_util.h"


#ifdef __cplusplus
extern "C" {
#endif


#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
#endif /* TH_GROWBUF_H */