/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_calloc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/11/25 11:47:16 by thrieg #+# #+# */ /* Updated: 2025/12/08 15:36:52 by thrieg ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/ft_malloc.h" void *calloc(size_t nmemb, size_t size) { size_t real_size = nmemb * size; void *malloc_ret; if (real_size % ALLIGN_BYTES) real_size = ((real_size / ALLIGN_BYTES) + 1) * ALLIGN_BYTES; malloc_ret = malloc(real_size); if (!malloc_ret) return (NULL); // pthread_mutex_lock(&g_mut); ft_memset(malloc_ret, 0, real_size); // no need to lock because pointer is internal until we return it, user can't call any of our function on it // pthread_mutex_unlock(&g_mut); return (malloc_ret); }