maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_calloc.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_calloc.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rmikhayl <rmikhayl@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/12/17 17:25:26 by rmikhayl #+# #+# */
9/* Updated: 2023/12/17 17:25:26 by rmikhayl ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15/* *************************** ft_calloc ************************************ */
16/* Allocates zero-initialized memory for 'count' elements of 'size'. */
17/* Returns a pointer to memory or NULL on failure/overflow. */
18/* */
19/* In layman's terms: It's like reserving a series of boxes (memory) and */
20/* ensuring they're all empty before you begin to use them. */
21/* ************************************************************************** */
22
23void *ft_calloc(size_t count, size_t size)
24{
25 void *ptr;
26
27 if (size != 0 && count > SIZE_MAX / size)
28 return (NULL);
29 ptr = malloc(count * size);
30 if (!ptr)
31 return (NULL);
32 ft_memset(ptr, 0, count * size);
33 return (ptr);
34}
void * ft_calloc(size_t count, size_t size)
Definition ft_calloc.c:23
void * ft_memset(void *s, int c, size_t n)
Definition ft_memset.c:28