Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_calloc.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_calloc.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: raphalme <raphalme@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/12/29 19:00:00 by raphalme #+# #+# */
9/* Updated: 2026/04/14 10:45:22 by raphalme ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "../includes/libft.h"
14
15
26void *ft_calloc(size_t nmemb, size_t size)
27{
28 void *ptr;
29 size_t total_size;
30
31 if (nmemb == 0 || size == 0)
32 return (malloc(0));
33 if (nmemb > (size_t)-1 / size)
34 return (NULL);
35 total_size = nmemb * size;
36 ptr = malloc(total_size);
37 if (!ptr)
38 return (NULL);
39 ft_memset(ptr, 0, total_size);
40 return (ptr);
41}
void * ft_calloc(size_t nmemb, size_t size)
Allocates and zero-initializes an array.
Definition ft_calloc.c:26
void * ft_memset(void *s, int c, size_t len)
Fills a memory area with a byte value.
Definition ft_memset.c:23