53 lines
1.8 KiB
C
53 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_calloc.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/17 10:20:05 by kcolin #+# #+# */
|
|
/* Updated: 2024/10/19 18:12:22 by kcolin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include <stdlib.h>
|
|
|
|
void *ft_calloc(size_t nmemb, size_t size)
|
|
{
|
|
size_t bytes;
|
|
void *out;
|
|
|
|
bytes = nmemb * size;
|
|
if (nmemb != 0 && bytes / nmemb != size)
|
|
return (NULL);
|
|
else
|
|
{
|
|
out = malloc(bytes);
|
|
if (out != NULL)
|
|
ft_memset(out, 0, bytes);
|
|
return (out);
|
|
}
|
|
}
|
|
|
|
/* #include <stdio.h> */
|
|
/* #include <stdint.h> */
|
|
|
|
/* int main(void) */
|
|
/* { */
|
|
/* free(ft_calloc(0, sizeof(int))); */
|
|
/* free(calloc(0, sizeof(int))); */
|
|
/* printf("%p\t%p\n", */
|
|
/* ft_calloc(0, sizeof(int)), */
|
|
/* calloc(0, sizeof(int))); */
|
|
/* free(ft_calloc(1024, sizeof(int))); */
|
|
/* free(calloc(1024, sizeof(int))); */
|
|
/* printf("%p\t%p\n", */
|
|
/* ft_calloc(1024, sizeof(int)), */
|
|
/* calloc(1024, sizeof(int))); */
|
|
/* free(ft_calloc(SIZE_MAX, sizeof(int))); */
|
|
/* free(calloc(SIZE_MAX, sizeof(int))); */
|
|
/* printf("%p\t%p\n", */
|
|
/* ft_calloc(SIZE_MAX, sizeof(int)), */
|
|
/* calloc(SIZE_MAX, sizeof(int))); */
|
|
/* } */
|