-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
41 lines (37 loc) · 1.25 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
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <sde-silv@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/22 14:58:14 by sde-silv #+# #+# */
/* Updated: 2023/06/12 14:58:26 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
void *ft_memset(void *s, int c, size_t n)
{
unsigned char *p;
p = s;
while (n > 0)
{
*p = (unsigned char)c;
p ++;
n --;
}
return (s);
}
*/
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
size_t byte_size;
byte_size = nmemb * size;
ptr = malloc(byte_size);
if (!ptr)
return (NULL);
ft_memset(ptr, 0, byte_size);
return (ptr);
}