-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
29 lines (26 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: junkwama <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/10 12:58:11 by junkwama #+# #+# */
/* Updated: 2023/05/10 13:10:49 by junkwama ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
int bytes;
if (count + size < count || count + size < size)
return (NULL);
bytes = count * size;
ptr = malloc(bytes);
if (!ptr)
return (NULL);
while (bytes--)
((char *)ptr)[bytes] = 0;
return (ptr);
}