libft/ft_calloc.c
2023-12-12 17:30:46 +01:00

29 lines
1.1 KiB
C
Executable File

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/11 17:47:38 by fgras-ca #+# #+# */
/* Updated: 2023/02/21 10:45:58 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
if (!nmemb || !size)
return (malloc(0));
if ((nmemb * size) / size != nmemb)
return (NULL);
ptr = malloc(size * nmemb);
if (!ptr)
return (0);
ft_bzero(ptr, size * nmemb);
return (ptr);
}