1#ifndef COMPA_GENLIB_UTIL_MEMBUFFER_HPP
2#define COMPA_GENLIB_UTIL_MEMBUFFER_HPP
73inline constexpr size_t MEMBUF_DEF_SIZE_INC{5};
int memptr_cmp(memptr *m, const char *s)
Compares characters of strings passed for number of bytes. If equal for the number of bytes,...
void membuffer_destroy(membuffer *m)
Free's memory allocated for membuffer* m.
size_t size_inc
used to increase size; MUST be > 0; (read/write).
size_t capacity
total allocated memory without terminating null byte (read-only).
int membuffer_set_size(membuffer *m, size_t new_length)
Increases or decreases buffer cap so that at least 'new_length' bytes can be stored.
char * str_alloc(const char *str, size_t str_len)
Allocate memory and copy information from the input string to the newly allocated memory.
size_t length
length of buffer without terminating null byte (read-only).
void membuffer_attach(membuffer *m, char *new_buf, size_t buf_len)
Free existing memory in membuffer and assign the new buffer in its place.
void membuffer_init(membuffer *m)
Wrapper to membuffer_initialize().
int membuffer_append(membuffer *m, const void *buf, size_t buf_len)
Invokes function to appends data from a constant buffer to the buffer.
int membuffer_assign_str(membuffer *m, const char *c_str)
Wrapper function for membuffer_assign().
char * membuffer_detach(membuffer *m)
Detaches current buffer and returns it. The caller must free the returned buffer using free()....
int membuffer_append_str(membuffer *m, const char *c_str)
Invokes function to appends data from a constant string to the buffer.
char * buf
mem buffer; must not write beyond buf[length-1] (read/write).
size_t length
length of memory (read-only).
int memptr_cmp_nocase(memptr *m, const char *s)
Compares characters of 2 strings irrespective of the case for a specific count of bytes.
int membuffer_insert(membuffer *m, const void *buf, size_t buf_len, size_t index)
Allocates memory for the new data to be inserted. Does memory management by moving the data from the ...
char * buf
start of memory (read/write).
int membuffer_assign(membuffer *m, const void *buf, size_t buf_len)
Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf.
void membuffer_delete(membuffer *m, size_t index, size_t num_bytes)
Shrink the size of the buffer depending on the current size of the buffer and the input parameters....
pointer to a chunk of memory.
Maintains a block of dynamically allocated memory.