ft_calloc.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* ft_calloc.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: ll-hotel <ll-hotel@student.42lyon.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/11/07 17:17:28 by ll-hotel #+# #+# */ 9 /* Updated: 2023/11/08 16:05:44 by ll-hotel ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include <stdlib.h> 14 15 void *ft_calloc(size_t nmemb, size_t size) 16 { 17 unsigned char *p; 18 size_t i; 19 size_t bytes; 20 21 bytes = nmemb * size; 22 if ((bytes < nmemb && size) || (bytes < size && nmemb)) 23 return (0); 24 p = malloc(bytes); 25 if (!p) 26 return (0); 27 i = 0; 28 while (i < bytes) 29 p[i++] = 0; 30 return (p); 31 }