-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
28 lines (25 loc) · 1.13 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: doley <doley@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/30 22:01:04 by doley #+# #+# */
/* Updated: 2024/10/11 22:05:25 by doley ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
size_t total;
if (size && nmemb > SIZE_MAX / size)
return (NULL);
total = nmemb * size;
ptr = malloc(total);
if (!ptr)
return (NULL);
ft_memset(ptr, 0, total);
return (ptr);
}