63 if (new_length >= m->length) {
66 if (new_length <= m->capacity) {
71 diff = new_length - m->length;
72 alloc_len = MAXVAL(m->size_inc, diff) + m->capacity;
75 assert(new_length <= m->length);
78 if ((m->capacity - new_length) <= m->size_inc) {
81 alloc_len = new_length + m->size_inc;
84 assert(alloc_len >= new_length);
86 temp_buf = (
char*)realloc(m->buf, alloc_len + (
size_t)1);
87 if (temp_buf == NULL) {
89 alloc_len = new_length;
90 temp_buf = (
char*)realloc(m->buf, alloc_len + (
size_t)1);
91 if (temp_buf == NULL) {
92 return IXML_INSUFFICIENT_MEMORY;
97 m->capacity = alloc_len;
105 m->size_inc = MEMBUF_DEF_SIZE_INC;
107 m->length = (size_t)0;
108 m->capacity = (size_t)0;
132 if (return_code != 0) {
137 memcpy(m->buf, buf, buf_len);
181 if (index > m->length) {
182 return IXML_INDEX_SIZE_ERR;
185 if (buf == NULL || buf_len == (
size_t)0) {
190 if (return_code != 0) {
195 memmove(m->buf + index + buf_len, m->buf + index, m->length - index);
196 memcpy(m->buf + index, buf, buf_len);
197 m->length += buf_len;
199 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)