#include #include #include "mwastring.h" void init_string(MWA_STRING *string, apr_pool_t *pool) { memset(string, 0, sizeof(MWA_STRING)); string->pool = pool; } void append_string(MWA_STRING *string, const char *in_data, int in_size) { int needed_size; if (in_size == 0) in_size = strlen(in_data); needed_size = string->size+in_size; if (string->data == NULL || needed_size > string->capacity) { char *new_data; while (string->capacity < needed_size+1) string->capacity += CHUNK_SIZE; //new_data = apr_palloc(string->pool, string->capacity); new_data = malloc(string->capacity); if (string->data != NULL) { memcpy(new_data, string->data, string->size); } /* don't have to free existing data since it from a pool */ string->data = new_data; } memcpy(string->data+string->size, in_data, in_size); string->size = needed_size; /* always null-terminate, we have space becase of the +1 above */ string->data[string->size] = '\0'; }