-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrylist.c
56 lines (43 loc) · 927 Bytes
/
entrylist.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "common.h"
#include "shell.h"
#ifndef NULL
#define NULL ( ( void* )0 )
#endif
int init_entry_list(SHELL_ENTRY_LIST* list)
{
memset(list, 0, sizeof(SHELL_ENTRY_LIST));
return 0;
}
int add_entry_list(SHELL_ENTRY_LIST* list, SHELL_ENTRY* entry)
{
SHELL_ENTRY_LIST_ITEM* newItem;
newItem = (SHELL_ENTRY_LIST_ITEM*)malloc(sizeof(SHELL_ENTRY_LIST_ITEM));
newItem->entry = *entry;
newItem->next = NULL;
if (list->count == 0)
list->first = list->last = newItem;
else
{
list->last->next = newItem;
list->last = newItem;
}
list->count++;
return 0;
}
void release_entry_list(SHELL_ENTRY_LIST* list)
{
SHELL_ENTRY_LIST_ITEM* currentItem;
SHELL_ENTRY_LIST_ITEM* nextItem;
if (list->count == 0)
return;
nextItem = list->first;
do
{
currentItem = nextItem;
nextItem = currentItem->next;
free(currentItem);
} while (nextItem);
list->count = 0;
list->first = NULL;
list->last = NULL;
}