-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
34 lines (31 loc) · 1.22 KB
/
ft_calloc.c
File metadata and controls
34 lines (31 loc) · 1.22 KB
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: lbiasuz <lbiasuz@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/10 22:47:16 by lbiasuz #+# #+# */
/* Updated: 2022/04/30 03:07:22 by lbiasuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
char *dest;
int check;
unsigned int i;
i = 0;
check = nmemb > size;
if ((nmemb * size) < ((nmemb * check) + (size * !check)))
return (NULL);
dest = malloc(nmemb * size);
if (!dest)
return (NULL);
while (i < (nmemb * size))
{
dest[i] = '\0';
i++;
}
return (dest);
}