-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
31 lines (28 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: myoshie <myoshie@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/08 05:00:25 by myoshie #+# #+# */
/* Updated: 2022/05/31 01:25:07 by myoshie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
if (size != 0 && SIZE_MAX / size < count)
return (NULL);
if (count == 0 || size == 0)
{
count = 1;
size = 1;
}
ptr = malloc(size * count);
if (!ptr)
return (NULL);
ft_bzero(ptr, size * count);
return (ptr);
}