#include "config.h"typedef struct dn { char *data; size_t isize; uint32_t count; uint32_t avail; /* Default item for zero-filling */ void *dflt;} dynarray;/* * Initialise a dynamic array. * Parameters: item size, default item for filling. * Will return NULL on error. */dynarray *dynarray_init(size_t isize, const void *dflt);/* Deinitialise the dynamic array. Frees allocated storage. */void dynarray_free(dynarray **d);/* * Delete n consecutive items from an array at position pos. * Requires that pos + nitems is lower than the length of the array. */void dynarray_del(dynarray *d, const uint32_t pos, const uint32_t nitems);/* * Put n items at a given position, possibly overwriting others. * Will resize the array if needed. If pos is larger than previous size, will * pad with default items. * Returns true if item was stored without errors. */int dynarray_put(dynarray *d, const uint32_t pos, const void *n, \ const uint32_t nitems);/* * Insert n items at a given position, moving others above. * Will resize the array if needed. If pos is larger than previous size, will * pad with default items. * Returns true if item was stored without errors. */int dynarray_insert(dynarray *d, const uint32_t pos, const void *n, \ const uint32_t nitems);/* Add n items to the end of the array. Will resize the array if needed. * Returns true if item was appended without errors. */int dynarray_append(dynarray *d, const void *n, const uint32_t nitems);/* * Get a pointer to internal dynarray data at position pos. * The data shouldn't be modified using this pointer, use put, insert or append * instead. * The pointer returned may be invalid after next put/append/insert. */const void *dynarray_peek(const dynarray *d, const uint32_t pos);/* * Get n consecutive items from an array at position pos. * Requires that pos + nitems is lower than the length of the array. * Returns a copy of the items - don't forget to free it when not needed. */void *dynarray_get(const dynarray *d, uint32_t pos, const uint32_t nitems);/* * Resize the dynarray, possibly truncating data. Only do this when the amount * of data is known or to trim the automatically sized array to a required size. * Will fill new space with default elements. */int dynarray_resize(dynarray *d, const uint32_t nitems);