| 178 | } |
| 179 | |
| 180 | struct strbuf **strbuf_split_buf(const char *str, size_t slen, |
| 181 | int terminator, int max) |
| 182 | { |
| 183 | struct strbuf **ret = NULL; |
| 184 | size_t nr = 0, alloc = 0; |
| 185 | struct strbuf *t; |
| 186 | |
| 187 | while (slen) { |
| 188 | int len = slen; |
| 189 | if (max <= 0 || nr + 1 < max) { |
| 190 | const char *end = memchr(str, terminator, slen); |
| 191 | if (end) |
| 192 | len = end - str + 1; |
| 193 | } |
| 194 | t = xmalloc(sizeof(struct strbuf)); |
| 195 | strbuf_init(t, len); |
| 196 | strbuf_add(t, str, len); |
| 197 | ALLOC_GROW(ret, nr + 2, alloc); |
| 198 | ret[nr++] = t; |
| 199 | str += len; |
| 200 | slen -= len; |
| 201 | } |
| 202 | ALLOC_GROW(ret, nr + 1, alloc); /* In case string was empty */ |
| 203 | ret[nr] = NULL; |
| 204 | return ret; |
| 205 | } |
| 206 | |
| 207 | void strbuf_add_separated_string_list(struct strbuf *str, |
| 208 | const char *sep, |
no test coverage detected