42_libft/ft_calloc.c

27 lines
1.1 KiB
C
Raw Normal View History

2022-09-27 10:29:23 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:09:01 by cchauvet #+# #+# */
2022-10-28 12:29:59 -04:00
/* Updated: 2022/10/28 17:31:12 by cchauvet ### ########.fr */
2022-09-27 10:29:23 -04:00
/* */
/* ************************************************************************** */
#include "libft.h"
2022-10-04 08:21:55 -04:00
void *ft_calloc(size_t nmemb, size_t size)
2022-09-27 10:29:23 -04:00
{
2022-10-04 16:04:23 -04:00
void *tab;
2022-09-27 10:29:23 -04:00
2022-10-04 16:04:23 -04:00
if (nmemb != 0 && (size_t)(nmemb * size) / nmemb != size)
return (NULL);
2022-09-27 10:29:23 -04:00
tab = malloc(nmemb * size);
2022-10-04 08:21:55 -04:00
if (tab == NULL)
return (NULL);
2022-09-27 10:29:23 -04:00
ft_bzero(tab, nmemb * size);
return (tab);
}