alistair
4 years ago
2 changed files with 47 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||||
|
#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); |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
#include <stdlib.h> |
||||||
|
#include <err.h> |
||||||
|
|
||||||
|
struct chicken_array { |
||||||
|
void **items; |
||||||
|
int length; |
||||||
|
int size; |
||||||
|
}; |
||||||
|
|
||||||
|
typedef struct chicken_array Chicken_Array; |
||||||
|
|
||||||
|
void chicken_array_extend(Chicken_Array, void *);
|
||||||
|
Chicken_Array get_fucked_array(int);
|
||||||
|
void delete_chicken_array(Chicken_Array *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue