diff options
Diffstat (limited to 'libft/ft_calloc.c')
-rw-r--r-- | libft/ft_calloc.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100644 index 0000000..b7c710d --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/09/28 05:18:38 by kdx #+# #+# */ +/* Updated: 2022/09/29 20:49:25 by kdx ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stdint.h> + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (nmemb != 0 && (size_t)(nmemb * size) / nmemb != size) + return (NULL); + ptr = malloc(nmemb * size); + if (ptr == NULL) + return (ptr); + ft_bzero(ptr, nmemb * size); + return (ptr); +} |