list.c
new function list_to_create
Showing
1 changed file
with
21 additions
and
0 deletions
... | @@ -303,3 +303,24 @@ list_set_destroy_item (list_t list, void (*destroy_item)(void *item)) | ... | @@ -303,3 +303,24 @@ list_set_destroy_item (list_t list, void (*destroy_item)(void *item)) |
303 | return EINVAL; | 303 | return EINVAL; |
304 | list->destroy_item = destroy_item; | 304 | list->destroy_item = destroy_item; |
305 | } | 305 | } |
306 | |||
307 | int | ||
308 | list_to_array (list_t list, void **array, size_t count, size_t *pcount) | ||
309 | { | ||
310 | size_t total = 0; | ||
311 | |||
312 | if (list != NULL) | ||
313 | { | ||
314 | size_t i; | ||
315 | struct list_data *current; | ||
316 | total = (count < list->count) ? count : list->count; | ||
317 | for (i = 0, current = list->head.next; i < total && current != &(list->head); current = current->next) | ||
318 | { | ||
319 | if (array) | ||
320 | array[i] = current->item; | ||
321 | } | ||
322 | } | ||
323 | if (pcount) | ||
324 | *pcount = total; | ||
325 | return 0; | ||
326 | } | ... | ... |
-
Please register or sign in to post a comment