-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
35 lines (32 loc) · 1.47 KB
/
ft_calloc.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pix <pix@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/17 23:48:42 by stales #+# #+# */
/* Updated: 2022/04/04 02:52:36 by pix ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/**
* @brief Allocates memory for an array of nmemb elements of size
* bytes each and returns a pointer to the allocated memory.
* The memory is set to zero.
*
* @param nmemb Length of array returned
* @param size Size in bytes of each element in the array
*
* @return (void) Pointer to the allocated memory all set to zero, return NULL
* nmemb or size is equal to zero, or on error.
*/
void *ft_calloc(t_size nmemb, t_size size)
{
void *ptr;
ptr = (void *)malloc(nmemb * size);
if (ptr)
ft_memset(ptr, 0, nmemb * size);
return (ptr);
}