-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
28 lines (25 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pabmart2 <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 15:47:45 by pabmart2 #+# #+# */
/* Updated: 2024/09/26 13:44:18 by pabmart2 ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
size_t total_size;
void *ptr;
if (size != 0 && nmemb > __SIZE_MAX__ / size)
return (NULL);
total_size = nmemb * size;
ptr = malloc(total_size);
if (!ptr)
return (NULL);
ft_bzero(ptr, total_size);
return (ptr);
}