-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
51 lines (43 loc) · 1.47 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
41
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/19 14:29:17 by julmuntz #+# #+# */
/* Updated: 2022/05/20 17:17:07 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nbr, size_t size)
{
void *ptr;
if (size != 0 && nbr > SIZE_MAX / size)
return (NULL);
ptr = malloc(nbr * size);
if (ptr == NULL)
return (NULL);
ft_bzero(ptr, size * nbr);
return (ptr);
}
/*
#include <stdio.h>
int main(int arc, char **arv)
{
int nbr;
int *ptr;
if (arc == 2)
{
nbr = arv[1][0];
puts("\n- calloc");
ptr = calloc(nbr, sizeof(int));
printf("'%ls'\n", ptr);
free(ptr);
puts("\n- ft_calloc");
ptr = ft_calloc(nbr, sizeof(int));
printf("'%ls'\n", ptr);
free(ptr);
}
}
*/