#include #include "list.h" int create_node( list_t **head, int size ) { if( (*head = (list_t*)malloc( size )) == NULL ) return -1; (*head)->next = NULL; return 0; } int add_node( list_t **head, list_t *node ) { list_t *tmp = *head; if( *head == NULL ) { *head = node; } while( tmp->next ) { tmp = tmp->next; } tmp->next = node; return 0; } int remove_node( list_t **head, list_t *node ) { list_t *tmp = *head; if( node == NULL || *head == NULL ) return -1; while( tmp ) { if( tmp->next == node ) break; tmp = tmp->next; } tmp->next = node->next; free( node ); return 0; } int cleanup_list( list_t **head ) { list_t *tmp; do { tmp = (*head)->next; free( *head ); *head = tmp; } while( tmp ); *head = NULL; return 0; }