tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
ft_calloc.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_calloc.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2023/10/25 14:33:28 by tgrekov #+# #+# */
9
/* Updated: 2023/11/06 19:16:56 by tgrekov ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
20
#include "
libft.h
"
21
34
void
*
ft_calloc
(
size_t
count,
size_t
size)
35
{
36
void
*ptr;
37
size_t
bsize;
38
39
if
(!count || !size)
40
return
(
ft_calloc
(1, 1));
41
bsize = count * size;
42
if
(bsize / count != size)
43
return
(0);
44
ptr = malloc(bsize);
45
if
(!ptr)
46
return
(0);
47
ft_bzero
(ptr, bsize);
48
return
(ptr);
49
}
ft_bzero
void ft_bzero(void *s, size_t n)
Write n zeroes to byte string at pointer s.
Definition
ft_bzero.c:28
ft_calloc
void * ft_calloc(size_t count, size_t size)
Allocates count * size bytes with malloc and returns a pointer to the result.
Definition
ft_calloc.c:34
libft.h
deps
libft
ft_calloc.c