| 108 | /* allocate space for a string */ |
| 109 | |
| 110 | char *string_alloc(string_alloc_t *a_str, size_t length) { |
| 111 | string_t *str; |
| 112 | char *ret; |
| 113 | |
| 114 | if (length <= 0) return NULL; |
| 115 | |
| 116 | // add to last string pool if we have space |
| 117 | if (a_str->nstrings) { |
| 118 | str = &a_str->strings[a_str->nstrings - 1]; |
| 119 | |
| 120 | if (str->used + length < a_str->max_length) { |
| 121 | ret = str->str + str->used; |
| 122 | str->used += length; |
| 123 | return ret; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // increase the max length if needs be |
| 128 | if (length > a_str->max_length) a_str->max_length = length; |
| 129 | |
| 130 | // need a new string pool |
| 131 | str = new_string_pool(a_str); |
| 132 | |
| 133 | if (NULL == str) return NULL; |
| 134 | |
| 135 | str->used = length; |
| 136 | return str->str; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /* equivalent to strdup */ |
no test coverage detected