You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
748 B
31 lines
748 B
#include "erray.h" |
|
|
|
void chicken_array_extend(Chicken_Array array, void *item) { |
|
if (1 + array.length == array.size) { |
|
array.items = reallocarray(array.items, array.length + 1, sizeof(void *)); |
|
if (array.items) { |
|
array.length++; |
|
} else { |
|
errx(9, "Malloc error"); |
|
} |
|
} |
|
} |
|
|
|
Chicken_Array get_chicken_array(int length) { |
|
Chicken_Array array; |
|
if (length != 0) { |
|
array.items = calloc(length, sizeof(void*)); |
|
if (!array.items) { |
|
errx(9, "Malloc error"); |
|
} |
|
} |
|
array.length = 0; |
|
array.size = length; |
|
return array; |
|
} |
|
|
|
/* Frees a heap array */ |
|
void delete_chicken_array(Chicken_Array *array) { |
|
free(array->items); |
|
free(array); |
|
}
|
|
|