-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
36 lines (33 loc) · 1.27 KB
/
ft_calloc.c
File metadata and controls
36 lines (33 loc) · 1.27 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
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dporhomo <dporhomo@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/14 15:59:08 by dporhomo #+# #+# */
/* Updated: 2025/11/15 14:47:03 by dporhomo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
size_t total_size;
size_t i;
char *ptr;
if (nmemb == 0 || size == 0)
return (malloc(1));
total_size = nmemb * size;
if (nmemb > 0 && total_size / nmemb != size)
return (NULL);
ptr = (char *)malloc(total_size);
if (ptr == NULL)
return (NULL);
i = 0;
while (i < total_size)
{
ptr[i] = 0;
i++;
}
return ((void *)ptr);
}