-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
32 lines (29 loc) · 1.21 KB
/
Copy pathft_calloc.c
File metadata and controls
32 lines (29 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
31
32
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gargrigo <gargrigo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/09 17:37:05 by gargrigo #+# #+# */
/* Updated: 2026/02/09 19:27:22 by gargrigo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdint.h>
#include <stdlib.h>
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
size_t total;
if (nmemb == 0 || size == 0)
return (malloc(0));
if (nmemb > SIZE_MAX / size)
return (NULL);
total = nmemb * size;
ptr = malloc(total);
if (!ptr)
return (NULL);
ft_memset(ptr, 0, total);
return (ptr);
}