refactor: move dynarray into own module
All checks were successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/test-mem Pipeline was successful

This commit is contained in:
Jef Roosens 2023-02-23 09:54:50 +01:00
parent e5f0ac8dec
commit caee502382
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
7 changed files with 69 additions and 71 deletions

34
include/vieter_dynarray.h Normal file
View file

@ -0,0 +1,34 @@
#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