-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
33 lines (29 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edboutil <edboutil@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/13 14:41:16 by edboutil #+# #+# */
/* Updated: 2022/11/25 13:25:31 by edboutil ### ########lyon.fr */
/* */
/* ************************************************************************** */
/*
** DESCRIPTION:
** The calloc() function contiguously allocates enough space for count
** objects that are size bytes of memory each and returns a pointer to the
** allocated memory. The allocated memory is filled with bytes of value zero.
*/
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
if (count != 0 && (SIZE_MAX / count < size))
return (0);
ptr = malloc(count * size);
if (!ptr)
return (NULL);
ft_bzero(ptr, size * count);
return (ptr);
}