mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Make improvements
This commit is contained in:
parent
3e4fd4b0ad
commit
e44a0cf6f8
256 changed files with 23100 additions and 2294 deletions
16
third_party/chibicc/strarray.c
vendored
Normal file
16
third_party/chibicc/strarray.c
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "third_party/chibicc/chibicc.h"
|
||||
|
||||
void strarray_push(StringArray *arr, char *s) {
|
||||
if (!arr->data) {
|
||||
arr->data = calloc(8, sizeof(char *));
|
||||
arr->capacity = 8;
|
||||
}
|
||||
|
||||
if (arr->capacity == arr->len) {
|
||||
arr->data = realloc(arr->data, sizeof(char *) * arr->capacity * 2);
|
||||
arr->capacity *= 2;
|
||||
for (int i = arr->len; i < arr->capacity; i++) arr->data[i] = NULL;
|
||||
}
|
||||
|
||||
arr->data[arr->len++] = s;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue