|
hl7parse
|
generic growing buffer library More...
#include <stdlib.h>#include <string.h>

Go to the source code of this file.
Classes | |
| struct | buf |
| dynamically growing generic bytearray More... | |
Typedefs | |
| typedef struct buf | buf_t |
| dynamically growing generic bytearray | |
Functions | |
| buf_t * | new_buf_t () |
| allocate initial memory | |
| void | free_buf (buf_t *buffer) |
| release all memory of buffer More... | |
| int | append_buf_str (buf_t *buffer, int size, unsigned char *data) |
| add data to buffer More... | |
| int | append_bufc (buf_t *buffer, unsigned char c) |
| append a character More... | |
generic growing buffer library
| int append_buf_str | ( | buf_t * | buffer, |
| int | size, | ||
| unsigned char * | data | ||
| ) |
add data to buffer
we excpect buffer always to be at least 1 byte long and terminated by \0.
The output buffer will always be \0 terminated.
to prevent constant reallocs() on small chunks, the allocated size buf_t.allocated is doubled when more memory is required.
If a large chunk is added that is larger than buf_t.allocated * 2 then the current size + the size of the new chunk is calculated and reallocated.
| buffer | the buffer to work on |
| size | size of the new chunk |
| data | byte array to papend |
input trats data as byte array and requires an absolute length. internally we set a '\0' char to the last byte, potentially loosing data.
on the other hand append_bufc() doesn't care, how should it.
| int append_bufc | ( | buf_t * | buffer, |
| unsigned char | c | ||
| ) |
append a character
slightly faster than append_buf_str(...) which takes a C character as input.
| buffer | the buffer to work on |
| c | the character to add |
| void free_buf | ( | buf_t * | buffer | ) |
release all memory of buffer
| buffer |
1.8.13