-
Notifications
You must be signed in to change notification settings - Fork 0
/
realloc.c
38 lines (35 loc) · 857 Bytes
/
realloc.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
/*
** realloc.c for in /u/epitech_2012/brenne_t/cu/rendu/c/malloc
**
** Made by thomas brennetot
** Login <[email protected]>
**
** Started on Fri Mar 27 15:16:59 2009 thomas brennetot
** Last update Sat Mar 28 19:10:25 2009 thomas brennetot
*/
#include "pointh.h"
void *realloc(void *ptr, size_t size)
{
void *ptr_new;
t_malloc *st_malloc;
if (ptr == NULL)
return (malloc(size));
st_malloc = find_associate_struct_of_alloc_space(ptr);
if (st_malloc == NULL)
{
my_putstr("realloc(toto): warning: junk pointer, too high to make sense\n");
return (NULL);
}
if (st_malloc->size_block < size)
{
ptr_new = malloc(size);
memmove(ptr_new, ptr, st_malloc->size_ask);
my_free(st_malloc);
}
else
{
st_malloc->size_ask = size;
ptr_new = st_malloc;
}
return (ptr_new);
}