-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
30 lines (27 loc) · 1.21 KB
/
ft_calloc.c
File metadata and controls
30 lines (27 loc) · 1.21 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alucas-e <alucas-e@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/18 15:21:58 by alucas-e #+# #+# */
/* Updated: 2024/10/29 14:18:20 by alucas-e ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
size_t total_size;
if (size != 0 && nmemb > SIZE_MAX / size)
return (NULL);
if (nmemb == 0 || size == 0)
return (malloc(0));
total_size = nmemb * size;
ptr = malloc(total_size);
if (!ptr)
return (NULL);
ft_memset(ptr, 0, total_size);
return (ptr);
}