util.c (388B)
1 #include <stdlib.h> 2 3 #include "util.h" 4 5 Array * 6 newarray(size_t s) 7 { 8 Array *a; 9 a = malloc(sizeof(Array)); 10 *a = (Array){NULL, s, 0}; 11 return a; 12 } 13 14 void 15 freearray(Array *a) 16 { 17 free(a->p); 18 a->p = NULL; 19 free(a); 20 } 21 22 void * 23 arrayinc(Array *v) 24 { 25 v->n++; 26 v->p = realloc(v->p, v->n * v->s); 27 return v->p + (v->n - 1) * v->s; 28 } 29 30 void * 31 arrayget(Array *v, int n) 32 { 33 return v->p + n * v->s; 34 }