-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
32 lines (29 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: crea <crea@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 16:53:28 by crea #+# #+# */
/* Updated: 2024/02/05 14:40:03 by crea ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* ft_calloc:
** Allocates memory for an array of 'count' elements of 'size' bytes each,
** initializes all bytes to 0, and returns a pointer to the allocated memory.
*/
void *ft_calloc(size_t count, size_t size)
{
size_t tot_size;
void *dest;
tot_size = count * size;
if (count && size && (4294967295U / size <= count))
return (NULL);
dest = malloc(tot_size);
if (!dest)
return (NULL);
ft_bzero(dest, (tot_size));
return (dest);
}