copy on git
This commit is contained in:
commit
42653de246
205 changed files with 7459 additions and 0 deletions
29
srcs/ft_calloc.c
Normal file
29
srcs/ft_calloc.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/25 11:47:16 by thrieg #+# #+# */
|
||||
/* Updated: 2025/11/28 16:41:16 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue