-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
33 lines (30 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kotainou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 16:28:27 by kotainou #+# #+# */
/* Updated: 2023/05/22 18:52:59 by kotainou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *ans;
size_t i;
i = 0;
if (size != 0 && count > SIZE_MAX / size)
return (NULL);
else if (count == 0 || size == 0)
{
count = 1;
size = 1;
}
ans = (void *)malloc(count * size);
if (ans == NULL)
return (NULL);
ft_bzero(ans, count * size);
return (ans);
}