-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
70 lines (65 loc) · 1.71 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kakiba <kotto555555@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/11 23:57:14 by kakiba #+# #+# */
/* Updated: 2022/07/23 19:50:23 by kakiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *m;
if (size == 0 || count == 0)
{
count = 1;
size = 1;
}
if (count <= __SIZE_MAX__ / size)
{
m = malloc(size * count);
if (m != NULL)
ft_bzero(m, size * count);
}
else
m = NULL;
return (m);
}
/*
int main(void)
{
int *s1;
int *s2;
size_t x = 1234;
size_t y = 10;
s1 = ft_calloc(sizeof(int), x);
// s1 = malloc(sizeof(int) * x);
printf("calloc()\n");
for(int i = 0; i < y; ++i)
{
printf("%p\n", s1 + i);
printf("%d\n", s1[i]);
}
free (s1);
// for(int i = 0; i < y; ++i)
// {
// printf("%d\n", s1[i]);
// }
s2 = calloc(sizeof(int), x);
printf("calloc()\n");
for(int i = 0; i < y; ++i)
{
printf("%p\n", s2 + i);
printf("%d\n", s2[i]);
}
free (s2);
// for(int i = 0; i < y; ++i)
// {
// printf("%d\n", s2[i]);
// }
return 0;
}
*/