-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue.c
executable file
·62 lines (52 loc) · 1.3 KB
/
queue.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
56
57
58
59
60
61
62
#include <stdio.h>
#include <string.h>
#include "queue.h"
void queue_push(struct queue_item* pFirstItem, struct queue_item* pNewItem)
{
if (pFirstItem->next_item != NULL)
{
struct queue_item* ptr = pFirstItem->next_item;
while(ptr->next_item != NULL)
{
ptr = ptr->next_item;
}
ptr->next_item = pNewItem;
}
else
{
pFirstItem->next_item = pNewItem;
}
}
struct queue_item* queue_pop(struct queue_item* pFirstItem)
{
if (pFirstItem->next_item == NULL)
{
return NULL;
}
else
{
struct queue_item* pResult = pFirstItem->next_item;
pFirstItem->next_item = pFirstItem->next_item->next_item;
return pResult;
}
}
struct queue_item* queue_create_item(uint8_t* packet, unsigned int length, char* interface)
{
struct queue_item* queue_new_item = ((queue_item*)(malloc(sizeof(queue_item))));
memcpy(queue_new_item->packet, packet, length);
queue_new_item->length = length;
queue_new_item->interface = interface;
queue_new_item->next_item = NULL;
return queue_new_item;
}
uint8_t queue_is_empty(struct queue_item* pFirstItem)
{
if (pFirstItem->next_item == NULL)
{
return 1;
}
else
{
return 0;
}
}