-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue_init.c
35 lines (31 loc) · 1.29 KB
/
queue_init.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* queue_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mihykim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/24 13:00:23 by mihykim #+# #+# */
/* Updated: 2020/03/24 18:01:42 by mihykim ### ########.fr */
/* */
/* ************************************************************************** */
#include "queue.h"
t_queue *queue_init(unsigned int max_size)
{
t_queue *queue;
queue = malloc(sizeof(t_queue));
if (queue == NULL)
return (NULL);
queue->max_size = max_size;
queue->last_index = -1;
queue->data = malloc(sizeof(void *) * max_size);
if (queue->data == NULL)
{
free(queue);
return (NULL);
}
return (queue);
}
/*
** line 19 : malloc size 'sizeof(t_queue)', not 'sizeof(t_queue) * max_size'
*/