cbuf.h 483 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef __libauthclient_cbuf_h
#define __libauthclient_cbuf_h 1

#include <sys/types.h>

/*
 * A dynamically sized memory buffer that can be appended to, and will
 * grow accordingly. It is optimized to perform well for a specific
 * size (the initial allocation).
 */

struct cbuf {
  char *buf;
  size_t alloc, size;
};

void cbuf_init(struct cbuf *cbuf, size_t alloc);
void cbuf_free(struct cbuf *cbuf);
void cbuf_append(struct cbuf *cbuf, const char *data, size_t size);

#endif