Commit 2ddc6851 2ddc68512560f42f9a7a18c50cb9f48d9312a9c8 by Alain Magloire

list.c

new function list_to_create
1 parent 7d2d7ecf
...@@ -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 }
......