-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
43 lines (40 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sizerese <sizerese@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/28 23:39:31 by sizerese #+# #+# */
/* Updated: 2023/09/06 21:54:56 by sizerese ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <limits.h>
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
size_t i;
i = 0;
if (size && count > UINT_MAX / size)
return (NULL);
i = size * count;
ptr = malloc(i);
if (!ptr)
return (NULL);
ft_bzero(ptr, i);
return (ptr);
}
/*
int main()
{
int *s1;
int i = 0;
s1 = ft_calloc(4, INT_MAX);
while (i < 4)
{
printf("%d", s1[i]);
i++;
}
}
*/