1
0
libft_new/mem/ft_calloc.c

37 lines
1.3 KiB
C
Raw Normal View History

2023-11-03 16:21:15 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
2024-02-04 15:11:02 +01:00
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
2023-11-03 16:21:15 +01:00
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 16:02:26 by adjoly #+# #+# */
2024-03-12 14:34:46 +01:00
/* Updated: 2024/03/04 10:10:58 by adjoly ### ########.fr */
2023-11-03 16:21:15 +01:00
/* */
/* ************************************************************************** */
2024-02-04 15:11:02 +01:00
#include "../libft.h"
2023-11-03 16:21:15 +01:00
2023-11-06 11:00:52 +01:00
void *ft_calloc(size_t nmemb, size_t size)
2023-11-03 16:21:15 +01:00
{
2024-03-12 14:34:46 +01:00
void *result;
2024-02-04 15:11:02 +01:00
size_t i;
2023-11-06 11:00:52 +01:00
2024-02-04 15:11:02 +01:00
i = 0;
2023-11-11 11:56:43 +01:00
if (nmemb == 0 || size == 0)
return (malloc(1));
2024-02-04 15:11:02 +01:00
if (((unsigned long long)(size * nmemb) > 4294967295))
return (NULL);
if ((int)size < 0 && (int)nmemb < 0)
return (NULL);
2023-11-06 11:00:52 +01:00
result = malloc(size * nmemb);
2024-02-04 15:11:02 +01:00
if (!result)
2023-11-06 11:00:52 +01:00
return (NULL);
2024-02-04 15:11:02 +01:00
while (i < (size * nmemb))
{
*(unsigned char *)(result + i) = '\0';
i++;
}
2023-11-06 11:00:52 +01:00
return (result);
2023-11-03 16:21:15 +01:00
}