-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_calloc.c
31 lines (28 loc) · 1.19 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: sel-mlil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/01 13:47:21 by sel-mlil #+# #+# */
/* Updated: 2024/11/01 20:07:02 by sel-mlil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *pointer;
if (size == 0 || nmemb == 0)
{
pointer = malloc(0);
return (pointer);
}
if (nmemb > SIZE_MAX / size)
return (NULL);
pointer = malloc(nmemb * size);
if (!pointer)
return (NULL);
ft_bzero(pointer, nmemb * size);
return (pointer);
}