/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_calloc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gvoelkne +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/04/20 09:15:29 by gvoelkne #+# #+# */ /* Updated: 2026/05/06 16:33:47 by gvoelkne ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" static void ft_bzero(void *s, size_t n) { unsigned char *arr; arr = s; while (n > 0) { *arr = '\0'; arr += 1; n -= 1; } } void *ft_calloc(size_t nmemb, size_t size) { unsigned char *res; if (size != 0 && (nmemb > (SIZE_MAX / size))) return (NULL); res = (unsigned char *)malloc(nmemb * size); if (!res) return (NULL); ft_bzero(res, (nmemb * size)); return ((void *)res); }