libvieter/include/vieter_dynarray.h

35 lines
724 B
C

#ifndef VIETER_DYNARRAY
#define VIETER_DYNARRAY
#include <stdlib.h>
#include <string.h>
typedef struct vieter_dynarray {
char **array;
size_t capacity;
size_t size;
} vieter_dynarray;
/*
* Allocate a dynamic array.
*/
vieter_dynarray *vieter_dynarray_init(size_t initial_capacity);
/*
* Initialise array (if it's not already initialised) and insert a string.
*/
void vieter_dynarray_add(vieter_dynarray *da, const char *s);
/*
* Deallocate dynamic array.
*/
void vieter_dynarray_free(vieter_dynarray *da);
/*
* Convert a vieter_dynarray into an array by freeing all its surrounding
* components and returning the underlying array pointer.
*/
char **vieter_dynarray_convert(vieter_dynarray *da);
#endif