-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
37 lines (33 loc) · 1.25 KB
/
ft_calloc.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchevrie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/13 12:53:43 by tchevrie #+# #+# */
/* Updated: 2022/11/08 18:20:30 by tchevrie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void *ft_memalloc(size_t size)
{
void *new;
size_t i;
new = (void *) malloc(size);
if (!new)
return (NULL);
i = 0;
while (i < size)
{
*(unsigned char *)(new + i) = 0;
i++;
}
return (new);
}
void *ft_calloc(size_t count, size_t size)
{
if (size != 0 && count > ((size_t) -1 / size))
return (NULL);
return (ft_memalloc(count * size));
}