47#include <umock/stdlib.hpp>
59 s = (
char*)malloc(str_len + (
size_t)1);
64 memcpy(s, str, str_len);
75 if (cmp == 0 && m->
length < strlen(s)) {
88 if (cmp == 0 && m->
length < strlen(s)) {
120 if (new_length >= m->
length) {
122 if (new_length <= m->capacity) {
126 diff = new_length - m->
length;
130 assert(new_length <= m->length);
137 alloc_len = new_length + m->
size_inc;
140 assert(alloc_len >= new_length);
142 temp_buf = (
char*)umock::stdlib_h.realloc(
143 m->
buf, alloc_len + (
size_t)1);
147 if (temp_buf == NULL) {
149 alloc_len = new_length;
150 temp_buf = (
char*)umock::stdlib_h.realloc(
151 m->
buf, alloc_len + (
size_t)1);
155 if (temp_buf == NULL) {
166 TRACE(
"Executing membuffer_init()")
174 TRACE(
"Executing membuffer_destroy()")
179 if (m->
buf !=
nullptr) {
180 umock::stdlib_h.free(m->
buf);
197 if (return_code != 0)
201 memcpy(m->
buf, buf, buf_len);
231 if (!buf || !buf_len) {
241 memmove(m->
buf + index + buf_len, m->
buf + index, m->
length - index);
242 memcpy(m->
buf + index, buf, buf_len);
260 if (index + num_bytes > m->
length) {
261 num_bytes = m->
length - index;
263 copy_len = (size_t)0;
266 copy_len = m->
length - (index + num_bytes);
268 memmove(m->
buf + index, m->
buf + index + num_bytes, copy_len);
269 new_length = m->
length - num_bytes;
273 assert(return_value == 0);
274 if (return_value != 0)
279 m->
buf[new_length] = 0;
#define UPNP_E_OUTOF_BOUNDS
The operation completed successfully.
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.
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.
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.
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 ...
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....
Manage blocks of dynamically allocated memory.
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).
size_t length
length of buffer without terminating null byte (read-only).
char * buf
mem buffer; must not write beyond buf[length-1] (read/write).
size_t length
length of memory (read-only).
char * buf
start of memory (read/write).
pointer to a chunk of memory.
Maintains a block of dynamically allocated memory.
#define UPNP_E_OUTOF_MEMORY
Not enough resources are currently available to complete the operation.
void membuffer_initialize(membuffer *m)
Initialize the buffer.
Specifications to be portable between different platforms.
Define macro for synced logging to the console for detailed info and debug.