- The documentation on the header allow u to see on the files where the header is inclued
32 lines
1.3 KiB
C
32 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_calloc.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/11/07 16:47:17 by rparodi #+# #+# */
|
|
/* Updated: 2025/09/05 16:25:35 by rparodi ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "memory.h"
|
|
#include <stdlib.h>
|
|
|
|
void *ft_calloc(size_t nmemb, size_t size)
|
|
{
|
|
size_t total;
|
|
char *to_return;
|
|
|
|
if (nmemb == 0 || size == 0)
|
|
return ((void *)malloc(1));
|
|
total = nmemb * size;
|
|
if (total / nmemb != size && total / size != nmemb)
|
|
return (NULL);
|
|
to_return = (char *)malloc(total);
|
|
if (to_return == NULL)
|
|
to_return = NULL;
|
|
else
|
|
ft_bzero(to_return, total);
|
|
return (to_return);
|
|
}
|