blob: 0f99ad0ac98ee1d14b22425e6e4f42bd2e5e9e8c (
plain)
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
|
#include <stdlib.h>
#include "fifo.h"
struct fifo *fifo_init(void)
{
struct fifo *f = malloc(sizeof(struct fifo));
if (f == NULL)
{
return NULL;
}
f->size = 0;
f->head = NULL;
f->tail = NULL;
return f;
}
void fifo_clear(struct fifo *fifo)
{
for (struct list *l = fifo->head; l != fifo->tail;)
{
struct list *tmp = l->next;
free(l->data);
free(l);
l = tmp;
}
if (fifo->tail)
{
free(fifo->tail->data);
free(fifo->tail);
}
fifo->head = NULL;
fifo->tail = NULL;
fifo->size = 0;
}
void fifo_destroy(struct fifo *fifo)
{
fifo_clear(fifo);
free(fifo);
}
|