-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
34 lines (30 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jados-sa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 21:17:55 by jados-sa #+# #+# */
/* Updated: 2024/10/29 19:41:27 by jados-sa ### ########.fr */
/* */
/* ************************************************************************** */
/* A memory allocator *
* Shall allocate unused space for an array of 'nelem' elements each of whose *
* size in byte is 'elsize'. The space shall be initialized to all bits 0. */
#include "libft.h"
void *ft_calloc(size_t nelem, size_t elsize)
{
size_t tsize;
void *space;
if (nelem == 0 || elsize == 0)
return (malloc(0));
tsize = nelem * elsize;
if (tsize / elsize != nelem)
return (NULL);
space = malloc(tsize);
if (!space)
return (NULL);
ft_bzero(space, tsize);
return (space);
}