-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
38 lines (35 loc) · 1.3 KB
/
ft_calloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_calloc.c :+: :+: */
/* +:+ */
/* By: splattje <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/10/04 17:56:30 by splattje #+# #+# */
/* Updated: 2023/10/31 16:38:06 by splattje ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *memory;
unsigned long long total;
if (nmemb == 0 || size == 0)
{
memory = malloc(1);
if (memory == NULL)
return (NULL);
ft_bzero(memory, 1);
return (memory);
}
total = size * nmemb;
if (total / size == nmemb)
{
memory = malloc(total);
if (memory == NULL)
return (NULL);
ft_bzero(memory, total);
return (memory);
}
return (NULL);
}