minishell
ft_calloc.c File Reference
#include "ft_mem.h"
#include "../ft_math/ft_math.h"
#include <stdlib.h>
Include dependency graph for ft_calloc.c:

Go to the source code of this file.

Functions

void * ft_calloc_nofill (size_t count, size_t size)
 
void * ft_calloc (size_t count, size_t size)
 

Function Documentation

◆ ft_calloc()

void* ft_calloc ( size_t  count,
size_t  size 
)

Definition at line 29 of file ft_calloc.c.

30 {
31  void *p_ret;
32 
33  p_ret = ft_calloc_nofill(count, size);
34  if (p_ret != NULL)
35  ft_bzero(p_ret, count * size);
36  return (p_ret);
37 }
void ft_bzero(void *s, size_t n)
Definition: ft_bzero.c:15
void * ft_calloc_nofill(size_t count, size_t size)
Definition: ft_calloc.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_calloc_nofill()

void* ft_calloc_nofill ( size_t  count,
size_t  size 
)

Definition at line 17 of file ft_calloc.c.

18 {
19  size_t bytes_to_allocate;
20 
21  if (!can_mulp(count, size))
22  return (NULL);
23  bytes_to_allocate = count * size;
24  if (bytes_to_allocate <= 0)
25  bytes_to_allocate = 1;
26  return (malloc(bytes_to_allocate));
27 }
bool can_mulp(size_t a, size_t b)
Definition: can_mul.c:50
Here is the call graph for this function:
Here is the caller graph for this function: