-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
33 lines (30 loc) · 1.35 KB
/
ft_calloc.c
File metadata and controls
33 lines (30 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jowagner <jowagner@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 14:01:39 by jowagner #+# #+# */
/* Updated: 2024/12/18 22:23:42 by jowagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Allocates memory for an array of elements, initializing them to zero.
*
* @param nmemb Number of elements to allocate.
* @param size Size of each element in bytes.
* @return A pointer to the allocated memory, or NULL if the allocation fails.
*/
void *ft_calloc(size_t nmemb, size_t size)
{
size_t total_size;
void *ptr;
total_size = nmemb * size;
ptr = malloc(total_size);
if (!ptr)
return (NULL);
ft_bzero(ptr, total_size);
return (ptr);
}