forked from justin-lathrop/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListItem.c
42 lines (34 loc) · 828 Bytes
/
ListItem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
*
*/
#include <stdlib.h>
#include "ListItem.h"
/*
* Allocates new memory for a ListItem_t
* then returns a pointer to it.
*/
ListItem_t * list_item_initialize(){
ListItem_t * li = (ListItem_t *) malloc( sizeof(ListItem_t) );
// Making sure there was enough memory for a 'ListItem_t' type 'li'.
if (li == NULL) {
printf("\nERROR: Insufficient memory. Terminating...");
exit(EXIT_FAILURE);
}
li->next = 0;
return(li);
}
/*
* Removes ListItem_t data and returns
* if successful or not.
*/
int list_item_remove(ListItem_t * li, list_item_remove_callback_func cb){
return( cb(li->data) );
}
/*
* Add ListItem_t data and returns
* if successful or not.
*/
int list_item_add(ListItem_t * li, void * data){
li->data = data;
return(1);
}