-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
37 lines (34 loc) · 1.27 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: igilbert <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/26 19:37:24 by ivan #+# #+# */
/* Updated: 2024/11/07 17:47:13 by igilbert ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *al;
size_t i;
i = 0;
if (count * size >= 2147483647 || ((int)count < 0 && (int)size < 0))
return (NULL);
if (count == 0 || size == 0)
{
al = malloc(sizeof(char));
return (al);
}
al = malloc(size * (count));
if (al == NULL)
return (NULL);
while (i < count * size)
{
((char *)al)[i] = 0;
i++;
}
return (al);
}