-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
49 lines (45 loc) · 1.62 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kyungkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/21 08:21:46 by kyungkim #+# #+# */
/* Updated: 2024/11/22 08:02:53 by kyungkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *result;
if (nmemb == 0 || size == 0)
{
result = malloc(0);
if (!result)
return (NULL);
return (result);
}
result = malloc(nmemb * size);
if (!result)
return (NULL);
ft_bzero(result, nmemb * size);
return (result);
}
/*
#include <unistd.h>
int main(void)
{
char *arr;
arr = ft_calloc(10,4);
for(int i = 0; i < 40;i++)
printf("%p %x\n", &arr[i], arr[i]);
printf("%p %x", calloc(10, 0), *((char *)calloc(10, 0)));
printf("%p %x\n", ft_calloc(10, 0), *((char *)ft_calloc(10, 0)));
//printf("%p %x\n",
ft_calloc(SIZE_MAX, SIZE_MAX),
*((char *)ft_calloc(SIZE_MAX, SIZE_MAX)));
printf("%p %x\n", calloc(SIZE_MAX, SIZE_MAX),
*((char *)calloc(SIZE_MAX, SIZE_MAX)));
}
*/