int main(int argc, char **argv) { ls(NULL); ls("test.c"); ls("../../"); cat("test.c"); dyn_array_t *strings = tokenizer("bob,sue,fred", ","); size_t end = dyn_array_size(strings); for (size_t i = 0; i < end; ++i) { printf("%s\n", *((char **) dyn_array_at(strings, i))); } dyn_array_destroy(strings); return 0; }
// Creates a dynamic array from a standard array dyn_array_t *dyn_array_import(const void *const data, const size_t count, const size_t data_type_size, void (*destruct_func)(void *)) { // Oh boy I'm going to be lazy with this dyn_array_t *dyn_array = NULL; // literally could not give us an overlapping pointer unless they guessed it // I'd just do a memcpy here instead of dyn_shift, but the dyn_shift branch for this is // short. DYN_SHIFT CANNOT fail if create worked properly, but we'll cleanup if it did anyway if (data && (dyn_array = dyn_array_create(count, data_type_size, destruct_func))) { if (count && !dyn_shift(dyn_array, 0, count, CREATE_GAP, (void *const) data)) { dyn_array_destroy(dyn_array); dyn_array = NULL; } } return dyn_array; }