Simple data structures / objects in plain C Snapshot
|
buffer that is owner of stuff that grows dynamically as you add stuff to it; This object owns the memory that it is holding. it also has length/size fields, no assumption data includes zeros or not - any data (not just strings). More...
Classes | |
struct | tagDBUF |
Typedefs | |
typedef struct tagDBUF | DBUF |
Functions | |
M_INLINE int | DBUF_init (DBUF *buf, size_t init_size) |
initialise a buffer | |
M_INLINE void | DBUF_reset (DBUF *buf) |
M_INLINE void | DBUF_free (DBUF *buf) |
free memory owned by a buffer | |
int | DBUF_add (DBUF *buf, void *data, size_t data_size) |
add stuff to a buffer | |
M_INLINE void * | DBUF_buffer (DBUF *buf) |
M_INLINE size_t | DBUF_size (DBUF *buf) |
buffer that is owner of stuff that grows dynamically as you add stuff to it; This object owns the memory that it is holding. it also has length/size fields, no assumption data includes zeros or not - any data (not just strings).
int DBUF_add | ( | DBUF * | buf, |
void * | data, | ||
size_t | data_size | ||
) |
add stuff to a buffer
Definition at line 4 of file dbuf.c.
{ size_t bs; uint8_t *nb; bs = buf->buf_size; if ( (buf->buf_used + data_size) > bs) { if (bs == 0) { bs = 1; } do { bs *= 2; } while( (buf->buf_used + data_size) > bs ); nb = (uint8_t *) realloc( buf->buf, bs ); if (!nb) { return -1; } buf->buf = nb; buf->buf_size = bs; } memcpy( buf->buf + buf->buf_used, data, data_size ); buf->buf_size = bs; buf->buf_used += data_size; return 0; }
M_INLINE void DBUF_free | ( | DBUF * | buf | ) |
M_INLINE int DBUF_init | ( | DBUF * | buf, |
size_t | init_size | ||
) |