int list_add_item(list *listo, void *item, char *name) { int name_length; char *new_name; if( list_is_full(listo) ) { if( listo->growable ) list_grow(listo); else return -1; } listo->names[listo->item_count] = NULL; if(name != NULL) { name_length = strlen(name); new_name = (char*) malloc(sizeof(char) * name_length + 1); strncpy(new_name, name, name_length); listo->names[listo->item_count] = new_name; } listo->items[listo->item_count] = item; listo->item_count++; return listo->item_count-1; }
bool_t list_add_to_end(list_t *list, list_item_t *item) { if(list_is_full(list)) { return FALSE; } if(list_is_empty(list)) { // Add first item list->first_item = item; list->last_item = item; item->next_item = NULL; item->previous_item = NULL; } else { // Append new item to last item item->previous_item = list->last_item; item->next_item = NULL; list->last_item->next_item = item; list->last_item = item; } // Increment item count (list->nr_of_items)++; return TRUE; }