-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealloc.c
More file actions
49 lines (42 loc) · 877 Bytes
/
realloc.c
File metadata and controls
49 lines (42 loc) · 877 Bytes
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
/*
** realloc.c for realloc in /home/chenne_a/rendu/tech2/PSU_2016_malloc
**
** Made by chennetier
** Login <arthur.chennetier@epitech.eu>
**
** Started on Sat Feb 11 18:03:52 2017 chennetier
** Last update Sat Feb 11 18:03:53 2017 chennetier
*/
#include <string.h>
#include "malloc.h"
void *calloc(size_t nmemb, size_t size)
{
void *new_tmp;
if ((new_tmp = malloc(size * nmemb)) != NULL)
bzero(new_tmp, (size * nmemb));
return (new_tmp);
}
void *realloc(void *ptr, size_t size)
{
t_meta *data;
void *new;
size = (size + 7) & ~7;
if (ptr == NULL)
return (malloc(size));
else if (size == 0)
{
free(ptr);
return (NULL);
}
else
{
data = ptr - SIZE_META;
if (data->size >= size)
return (ptr);
if ((new = malloc(size)) == NULL)
return (NULL);
memcpy(new, ptr, data->size);
free(ptr);
return new;
}
}