-
Notifications
You must be signed in to change notification settings - Fork 0
/
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: phelebra <xhelp00@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/10 17:07:51 by phelebra #+# #+# */
/* Updated: 2023/01/17 17:48:20 by phelebra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
if (nmemb == 0 || size == 0)
{
ptr = malloc(0);
return (ptr);
}
if ((nmemb * size) < nmemb || (nmemb * size) < size)
return (NULL);
ptr = malloc(nmemb * size);
if (!ptr)
return (NULL);
ft_bzero(ptr, nmemb * size);
return (ptr);
}