-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_allocs.c
52 lines (45 loc) · 1.48 KB
/
ft_allocs.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
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_malloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: escura <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 14:08:30 by escura #+# #+# */
/* Updated: 2024/05/08 15:20:45 by escura ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_alloc.h"
void *ft_malloc(size_t size)
{
t_allocs *allocs;
void *ptr;
allocs = ft_allocs(NULL);
if (allocs == NULL)
return (malloc(size));
ptr = malloc(size);
if (ptr == NULL)
{
printf("Memory allocation failed\n");
ft_destructor();
exit(EXIT_FAILURE);
}
add_allocnode(&allocs, create_alloc(ptr));
return (ptr);
}
static void ft_bzero(void *s, size_t n)
{
unsigned char *ptr;
ptr = s;
while (n-- > 0)
*ptr++ = 0;
}
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
ptr = ft_malloc(count * size);
if (ptr == NULL)
return (NULL);
ft_bzero(ptr, count * size);
return (ptr);
}