Repository navigation
Expand file tree
/
Copy pathutils_alloc.c
More file actions
43 lines (37 loc) · 1.35 KB
/
Copy pathutils_alloc.c
File metadata and controls
43 lines (37 loc) · 1.35 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
35
36
37
38
39
40
41
42
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_alloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpedraza <mpedraza@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/12 14:47:31 by mpedraza #+# #+# */
/* Updated: 2025/12/20 20:24:09 by mpedraza ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void *ft_memset(void *s, int c, size_t n)
{
size_t i;
i = 0;
while (i < n)
*((char *)(s + i++)) = c;
return (s);
}
static void ft_bzero(void *s, size_t n)
{
ft_memset(s, 0, n);
}
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
if (nmemb == 0 || size == 0)
return (malloc(0));
if (size != 0 && nmemb > SIZE_MAX / size)
return (NULL);
ptr = malloc(nmemb * size);
if (!ptr)
return (NULL);
ft_bzero(ptr, nmemb * size);
return (ptr);
}