-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
executable file
·40 lines (36 loc) · 1.34 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
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mframbou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/08 15:14:29 by mframbou #+# #+# */
/* Updated: 2021/10/18 14:50:52 by mframbou ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
static void *ft_memalloc(size_t size)
{
char *res;
size_t i;
res = (char *) malloc(size);
if (res)
{
i = 0;
while (i < size)
{
res[i] = 0;
i++;
}
}
return ((void *) res);
}
// If one of 2 args == 0, then just return malloc(0)
// Returning NULL didn't passed the hardcore test, so return
// the other possible value (source: man)
void *ft_calloc(size_t nmemb, size_t size)
{
return (ft_memalloc(nmemb * size));
}