Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo_bonus/ft_calloc_bonus.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_calloc_bonus.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/23 00:06:00 by yabtaour #+# #+# */
9
/* Updated: 2022/05/23 00:06:02 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers_bonus.h"
13
14
void *ft_memset(void *b, int c, size_t len)
15
{
16
size_t i;
17
unsigned char *ptr;
18
19
i = 0;
20
ptr = b;
21
while (len > 0)
22
{
23
ptr[i] = (unsigned char)c;
24
i++;
25
len--;
26
}
27
return (b);
28
}
29
30
void ft_bzero(void *s, size_t n)
31
{
32
s = ft_memset(s, '\0', n);
33
}
34
35
void *ft_calloc(int count, int size)
36
{
37
void *ptr;
38
int sizee;
39
40
sizee = count * size;
41
ptr = (void *)malloc(sizee);
42
if (ptr != NULL)
43
ft_bzero(ptr, sizee);
44
else
45
return (NULL);
46
return (ptr);
47
}
48
49