Add a new node to the list, to head, containing the specified 'value' * pointer as value. * * On error, NULL is returned and no operation is performed (i.e. the * list remains unaltered). * On success the 'list' pointer you pass to the function is returned. */
| 87 | * list remains unaltered). |
| 88 | * On success the 'list' pointer you pass to the function is returned. */ |
| 89 | list *listAddNodeHead(list *list, void *value) |
| 90 | { |
| 91 | listNode *node; |
| 92 | |
| 93 | if ((node = zmalloc(sizeof(*node), MALLOC_SHARED)) == NULL) |
| 94 | return NULL; |
| 95 | node->value = value; |
| 96 | if (list->len == 0) { |
| 97 | list->head = list->tail = node; |
| 98 | node->prev = node->next = NULL; |
| 99 | } else { |
| 100 | node->prev = NULL; |
| 101 | node->next = list->head; |
| 102 | list->head->prev = node; |
| 103 | list->head = node; |
| 104 | } |
| 105 | list->len++; |
| 106 | return list; |
| 107 | } |
| 108 | |
| 109 | /* Add a new node to the list, to tail, containing the specified 'value' |
| 110 | * pointer as value. |
no test coverage detected