1 /*
2  * music player command (mpc)
3  * Copyright 2003-2018 The Music Player Daemon Project
4  * http://www.musicpd.org
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "list.h"
22 
23 #include <stdlib.h>
24 #include <assert.h>
25 
makeList(void)26 List *makeList(void) {
27 	List * list = malloc(sizeof(List));
28 
29 	assert(list!=NULL);
30 
31 	list->firstNode = NULL;
32 	list->lastNode = NULL;
33 	list->numberOfNodes = 0;
34 
35 	return list;
36 }
37 
insertInListWithoutKey(List * list,void * data)38 void insertInListWithoutKey(List * list, void * data) {
39 	ListNode * node;
40 
41 	assert(list!=NULL);
42 	assert(data!=NULL);
43 
44 	node = malloc(sizeof(ListNode));
45 	assert(node!=NULL);
46 
47 	if(list->firstNode==NULL) {
48 		assert(list->lastNode==NULL);
49 		list->firstNode = node;
50 	}
51 	else {
52 		assert(list->lastNode!=NULL);
53 		assert(list->lastNode->nextNode==NULL);
54 		list->lastNode->nextNode = node;
55 	}
56 
57 	node->data = data;
58 	node->nextNode = NULL;
59 
60 	list->lastNode = node;
61 
62 	list->numberOfNodes++;
63 }
64 
freeList(void * list)65 void freeList(void * list) {
66 	ListNode * tmpNode;
67 	ListNode * tmpNode2;
68 
69 	assert(list!=NULL);
70 
71 	tmpNode = ((List *)list)->firstNode;
72 
73 	while(tmpNode!=NULL) {
74 		tmpNode2 = tmpNode->nextNode;
75 		free(tmpNode);
76 		tmpNode = tmpNode2;
77 	}
78 
79 	free(list);
80 }
81