-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
36 lines (31 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tauer <tauer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:29:17 by tauer #+# #+# */
/* Updated: 2023/11/06 15:29:17 by tauer ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
int tot;
tot = nmemb * size;
if (nmemb && tot / nmemb != size)
return (NULL);
ptr = (void *)malloc(tot);
if (!ptr)
return (NULL);
ft_bzero(ptr, tot);
return (ptr);
}
// int main(void)
// {
// void *test = ft_calloc(3, -5);
// free(test);
// return (0);
// }