cosmopolitan/third_party/chibicc/strarray.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
458 B
C
Raw Permalink Normal View History

2020-12-01 11:43:40 +00:00
#include "third_party/chibicc/chibicc.h"
void strarray_push(StringArray *arr, char *s) {
size_t i;
2020-12-01 11:43:40 +00:00
if (!arr->data) {
arr->data = calloc(8, sizeof(char *));
arr->capacity = 8;
}
if (arr->len + 1 == arr->capacity) {
arr->capacity += arr->capacity >> 1;
arr->data = realloc(arr->data, arr->capacity * sizeof(*arr->data));
for (i = arr->len; i < arr->capacity; i++) {
arr->data[i] = 0;
}
2020-12-01 11:43:40 +00:00
}
arr->data[arr->len++] = s;
}