-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
35 lines (32 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agras <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/05 20:23:59 by agras #+# #+# */
/* Updated: 2021/12/13 17:09:15 by agras ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include <stdlib.h>
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
int mem_size;
int i;
if (nmemb * size > 2147483647)
return (NULL);
mem_size = nmemb * size;
ptr = malloc(mem_size);
if (!ptr)
return (NULL);
i = 0;
while (i < mem_size)
{
((unsigned char *)ptr)[i] = '\0';
i++;
}
return (ptr);
}