-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_medium_malloc.c
39 lines (36 loc) · 1.38 KB
/
ft_medium_malloc.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_medium_malloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbres <sbres@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/04/18 18:56:03 by sbres #+# #+# */
/* Updated: 2014/04/20 19:35:19 by sbres ### ########.fr */
/* */
/* ************************************************************************** */
#include "malloc.h"
#include <stdlib.h>
void *ft_medium_malloc(size_t size)
{
t_data *tmp;
void *new_area;
tmp = pages.medium;
while ((tmp->is_free == 0 && tmp->size <= size) && tmp->next != NULL)
{
tmp = tmp->next;
}
if (tmp->size < size || tmp->is_free == 0)
return (NULL);
if (tmp->size == size)
{
tmp->is_free = 0;
return (tmp->ptr);
}
new_area = tmp->ptr;
new_area += size;
new_block(tmp->size - size, new_area, 1, &pages.medium);
tmp->is_free = 0;
tmp->size = size;
return (tmp->ptr);
}