c-libp2p/utils/linked_list.c

27 lines
620 B
C
Raw Permalink Normal View History

2017-02-20 13:19:22 +00:00
#include <stdlib.h>
#include "libp2p/utils/linked_list.h"
struct Libp2pLinkedList* libp2p_utils_linked_list_new() {
struct Libp2pLinkedList* out = (struct Libp2pLinkedList*)malloc(sizeof(struct Libp2pLinkedList));
if (out != NULL) {
out->item = NULL;
out->next = NULL;
}
return out;
}
void libp2p_utils_linked_list_free(struct Libp2pLinkedList* head) {
struct Libp2pLinkedList* current = head;
2017-02-20 14:31:59 +00:00
struct Libp2pLinkedList* next = NULL;
2017-02-20 13:19:22 +00:00
while (current != NULL) {
2017-02-20 14:31:59 +00:00
next = current->next;
2017-02-20 23:53:20 +00:00
if (current->item != NULL) {
2017-02-20 14:31:59 +00:00
free(current->item);
2017-02-20 23:53:20 +00:00
current->item = NULL;
}
2017-02-20 14:31:59 +00:00
free(current);
current = next;
2017-02-20 13:19:22 +00:00
}
}