66 if (new_length >= m->length) {
69 if (new_length <= m->capacity) {
74 diff = new_length - m->length;
75 alloc_len = MAXVAL(m->size_inc, diff) + m->capacity;
78 assert(new_length <= m->length);
81 if ((m->capacity - new_length) <= m->size_inc) {
84 alloc_len = new_length + m->size_inc;
87 assert(alloc_len >= new_length);
89 temp_buf = (
char*)realloc(m->buf, alloc_len + (
size_t)1);
92 alloc_len = new_length;
93 temp_buf = (
char*)realloc(m->buf, alloc_len + (
size_t)1);
95 return IXML_INSUFFICIENT_MEMORY;
100 m->capacity = alloc_len;
108 m->size_inc = MEMBUF_DEF_SIZE_INC;
110 m->length = (size_t)0;
111 m->capacity = (size_t)0;
135 if (return_code != 0) {
140 memcpy(m->buf, buf, buf_len);
184 if (index > m->length) {
185 return IXML_INDEX_SIZE_ERR;
188 if (!buf || buf_len == (
size_t)0) {
193 if (return_code != 0) {
198 memmove(m->buf + index + buf_len, m->buf + index, m->length - index);
199 memcpy(m->buf + index, buf, buf_len);
200 m->length += buf_len;
202 m->buf[m->length] = 0;
void ixml_membuf_destroy(ixml_membuf *m)
ixml_membuf clearing routine.
void ixml_membuf_init(ixml_membuf *m)
ixml_membuf initialization routine.
static int ixml_membuf_set_size(ixml_membuf *m, size_t new_length)
Increases or decreases buffer capacity so that at least 'new_length' bytes can be stored.
int ixml_membuf_assign_str(ixml_membuf *m, const char *c_str)
Copies a NULL terminated string to the ixml_buffer.
int ixml_membuf_append(ixml_membuf *m, const void *buf)
Appends one byte to the designated ixml_membuffer.
int ixml_membuf_append_str(ixml_membuf *m, const char *c_str)
Appends the contents of a NULL terminated string to the designated ixml_membuf.
int ixml_membuf_assign(ixml_membuf *m, const void *buf, size_t buf_len)
Copies the contents o a buffer to the designated ixml_membuf.
int ixml_membuf_insert(ixml_membuf *m, const void *buf, size_t buf_len, size_t index)